UIScrollView not scrolling with UItextfields

前端 未结 4 1434
滥情空心
滥情空心 2021-01-23 23:33

I am making a normal view where users can update their profiles. I followed these steps to make that view

  1. Created a new UIViewController
4条回答
  •  旧巷少年郎
    2021-01-23 23:36

    Overriding UIScrollView touchesShouldCancelInContentView method will solve this problem.

    According to Apple touchesShouldCancelInContentView is called before scrolling begins if touches have already been delivered to a subview of the scroll view. if it returns NO the touches will continue to be delivered to the subview and scrolling will not occur.

    By default this method returns NO if view is a UIControl. So the scroll doesn't happens for the UIControls.

    If we returns YES from this method the touches will not be delivered to subview, So the scroll will occurs.

    So override UIScrollView touchesShouldCancelInContentView like following

    @interface MyScrollView : UIScrollView
    
    @end
    
    @implementation MyScrollView
    
    - (BOOL)touchesShouldCancelInContentView:(UIView *)view{
        return YES;
    }
    
    @end
    

    NOTE: touchesShouldCancelInContentView method only calls if we set the canCancelContentTouches property to YES

    Hope this helps.

提交回复
热议问题