Reputation: 3334
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
, so the button is the superview.
All I want to do is pass a single-tap event from the UIScrollView
subview to the UIButton
superview, and have the UIButton
handle it as it would if the user tapped the button directly.
Setting the scroll view's userInteractionEnabled
property to NO
won't work for me because there is content the user can scroll. Doing so would defeat the purpose of the scroll view.
Is this possible? Thanks!
Upvotes: 2
Views: 5014
Reputation: 10251
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.
Upvotes: 1
Reputation: 2682
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.
Upvotes: 2
Reputation: 530
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.
Upvotes: 0