Pass touch from UIScrollView to superview (UIButton)

后端 未结 3 492
囚心锁ツ
囚心锁ツ 2020-12-20 02:44

Possibly a duplicate, but I couldn\'t find an exact answer to my problem searching SO tonight...

I have a UIButton which contains a UIScrollView

相关标签:
3条回答
  • 2020-12-20 02:46

    Like huoxinbird said, it's definitely not common to lay your views like that.

    In the case where you are solidly adamant about this, you could use UITapGestureRecognizer and have it call the button's target and selector.

    If you wanted to include the button highlight and such, then you may have to subclass UITapGestureRecognizer and forward the touchesEnded to the button.

    0 讨论(0)
  • 2020-12-20 02:49

    Create a subclass of scrollview and override

    -(BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view
    {
    return YES;
    }
    

    Also subclass the uibutton(Your superview) and handle touches in touches began.

    0 讨论(0)
  • 2020-12-20 03:08

    Usually you don't put scrollview within a button. Instead consider using a UIView as the superview of scrollview. Or tell us more about your use case, so I can understand why you have to design in this way.

    0 讨论(0)
提交回复
热议问题