pass scroll event from uibutton to uiscrollview

后端 未结 4 679
旧巷少年郎
旧巷少年郎 2021-02-14 15:59

i have horizontal UIScrollView which is extended from UIScrollView and i added UIButtons horizontally. i can only scroll out of the button

4条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-14 16:35

    If you subclass NSButton and make your button of that type and override the following in your subclass you can pass the events back to the parent view, in your case the scroll view

    The following would make the button never trigger an event and instead all would be dealt with by the parent view:

    - (void)touchesBegan: (NSSet *)touches withEvent:(UIEvent *)event {
        [self.nextResponder touchesBegan:touches withEvent:event];      
    }
    
    - (void)touchesMoved: (NSSet *)touches withEvent:(UIEvent *)event {
        [self.nextResponder touchesMoved:touches withEvent:event];  
    }
    
    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent*)event 
    {
        [self.nextResponder touchesEnded:touches withEvent:event];  
    }
    

    If you want to have the button deal with one of those events instead use

    [super touchesEnded:touches withEvent:event];
    

提交回复
热议问题