iPhone: adding button to scrollview makes button inaccessible to interaction

后端 未结 2 1628
傲寒
傲寒 2021-01-21 03:15

For some reason, the button initialized in the addBook method of my viewController won\'t respond to touches. The selector I\'ve assigned to it never triggers, nor does the UICo

相关标签:
2条回答
  • 2021-01-21 03:39

    THe UIScrollView might be catching all the touch events.

    Maybe try a combination of the following:

    _scrollView.delaysContentTouches = NO;
    _scrollView.canCancelContentTouches = NO;
    

    and

    bookView.userInteractionEnabled = YES;
    
    0 讨论(0)
  • 2021-01-21 03:50

    try to remove the [bookView autorelease]; and do it like this:

    // Add the new view/button combo to the scrollview.
    // THIS WORKS VISUALLY, BUT THE BUTTON IS UNRESPONSIVE :(
    [_scrollView addSubview:bookView];
    [bookView release];
    

    _scrollView.canCancelContentTouches = YES; should do the trick

    delaysContentTouches - is a Boolean value that determines whether the scroll view delays the handling of touch-down gestures. If the value of this property is YES, the scroll view delays handling the touch-down gesture until it can determine if scrolling is the intent. If the value is NO , the scroll view immediately calls touchesShouldBegin:withEvent:inContentView:. The default value is YES.

    canCancelContentTouches - is a Boolean value that controls whether touches in the content view always lead to tracking. If the value of this property is YES and a view in the content has begun tracking a finger touching it, and if the user drags the finger enough to initiate a scroll, the view receives a touchesCancelled:withEvent: message and the scroll view handles the touch as a scroll. If the value of this property is NO, the scroll view does not scroll regardless of finger movement once the content view starts tracking.

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