Be careful about ScrollerView

Source: Internet
Author: User

I encountered a problem during project development. I directly created a UIScrollerView ON THE UIViewController and added the UIScrollerView as a subview TO THE UIViewController,

Another UISlider component is added to UIScrollerView. During the gesture sliding process, it is difficult to slide to the UISlider control. During the Sliding Process, UIScrollerView is rolled,

The UISlider control does not slide, making people crazy.

 

I went to the Internet to learn more about UIScrollerView, and finally understood what the problem was.

The following is a summary of the predecessors, because I don't think his summary is detailed.

UIScrollView reloads the hitTest method. When you touch your finger, UIScrollView intercepts all events and waits for 150 ms. During this period, if no finger is moved, when the time ends, UIScrollView sends the tracking event to the subview without moving itself. When the finger moves before the end of the time, UIScrollView slides to cancel tracking.

 

 

It seems that this is a problem with UIScrollView. Drag the UISlider directly. When the touch time is within ms, UIScrollView considers it to be dragging itself, thus blocking the event. As a result, UISlider cannot accept the sliding event. However, if you press and hold UISlider for a while and then drag it again, the touch time exceeds 150 ms, so the sliding event will be sent to UISlider.

 

I tried several methods during this period. Only one method is feasible, namely to rewrite the hitTest method of UIScrollView: When sliding UISlider, The UIScrollView cannot be slide.

However, another problem occurs. My UIScrollerView inherits the UIScrollerView directly. In UIViewController, The UIScrollerView hitTest method cannot be rewritten. Therefore, you need to recreate a view to inherit the UIScrollerView, then rewrite the above method and import it to UIViewController.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.