Chubby said things------IOS ScrollView Action principle (a large scrollview contains a small scrollview, how to slide the small scrollview when the big scrollview sliding small motionless

Source: Internet
Author: User

Today I did a project, there is a need, is a big ScrollView contains a small scrollview, how to slide the small scrollview when the big ScrollView slide, the small srollview does not slide.

We know that when multiple views are superimposed, the touch event is on top of the view, but if the parent view is Uiscrollview, the touch sub-view may cause uiscrollview scrolling if the default.

Uiscrollview scrolling reason, you can see the Uiscrollview principle.

I am here to briefly describe how Uiscrollview works, when the finger touch, Uiscrollview will intercept the event, will wait for a period of time, if no finger does not move, when the time is over, Uiscrollview will send tracking events to the child view. At the end of the time, the finger moves, and the uiscrollview moves to make fun of sending tracking.

So, Uiscrollview's subclass wants to accept touch events, that is, when the user taps the view on Uiscrollview, it first processes the touch on the view without scrolling. In this case, you need to uiscrollview the subclass overload TouchesShouldBegin:withEvent:inContentView: To determine whether you accept the touch event in the child view.

-(BOOL) Touchesshouldbegin: (Nsset *) touches withevent: (Uievent *) event Incontentview: (UIView *) View {     NSLog (@ " The user clicked on the scroll on the view%@, whether to start scrolling scroll ", view);     Returns YES does not scroll scroll returns no is scroll scroll return     YES;}-(BOOL) Touchesshouldcancelincontentview: (UIView *) View {     NSLog (@ "user-clicked View%@", view);      No scroll can not scroll YES scroll can scroll     return no;

Rewritten-(BOOL) Touchesshouldbegin: (Nsset *) touches withevent: (Uievent *) event Incontentview: (UIView *) View method and-(BOOL) Touchesshouldcancelincontentview: (UIView *) View method.

where (BOOL) Touchesshouldbegin: (Nsset *) touches withevent: (Uievent *) event Incontentview: (UIView *) View, Is the user clicks the small ScrollView area, first triggers this method, when returns Yes, the touch event functions to the small ScrollView view (does not slide), when returns no, the big ScrollView can scroll up and down, the small scrollview does not slide.

-(BOOL) Touchesshouldcancelincontentview: (UIView *) view is to send tracking before, first function this method.

At the end of the ScrollView initialization, there are several properties to be set:

No send scrolling notifications but even if the fingers move scroll will not move. YES Send notification scroll can move     [Myscrollview Setcancancelcontenttouches:yes];     [Myscrollview Setbounces:no];     NO immediately notify TouchesShouldBegin:withEvent:inContentView to see if rolling scroll     [Myscrollview setdelayscontenttouches:no]; This is the key, the default is yes, not set to No is TouchesShouldBegin:withEvent:inContentView: May not be callback
Well, this is the perfect solution to the above problem.


Chubby said things------IOS ScrollView Action principle (a large scrollview contains a small scrollview, how to slide the small scrollview when the big scrollview sliding small motionless

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.