Bug fixes for Infinite carousel

Source: Internet
Author: User

Foreword: The last time realizes the automatic rolling of the carousel, but there are two bugs to be handled.

1. Stop Auto-scrolling when you drag and drop the control wheel.

2. When Tableview,textview or ScrollView are available on the same page, when dragging these controls: The Carousel stops auto-carousel, snaps, and when the controls are released: The Carousel is quickly wheeled, the jammed time is back up, and then it returns to normal.

cause: The control of the interface is created by the main thread, and the user's actions are also handled in the main thread. When the user drags another control, the main thread is busy with the drag and drop behavior, and it cannot handle the rolling events of the carousel at the same time .

Resolve Issue 1:

1> When you use the same code more than once, extract it as a method: There are two places in this demo: Add timer, remove timer

 //  add timer -( void  ) addtimer{Self.timer  = [Nstimer scheduledtimerwithtimeinterval:< Span style= "color: #800080;"    >1.0   Target:self selector: @selector (nextimage) Userinfo:nil Repeats:yes];  //  troubleshoot problems when dragging other controls when the picture carousel is not responding  Span style= "color: #008000;" >//  Gets the message loop of the current main thread and adds Self.timer to the main run loop.  Nsrunloopcommonmodes can handle multiple events at the same time. 
    [[Nsrunloop Currentrunloop] AddTimer:self.timer formode:nsrunloopcommonmodes];} // Removal Timer -(void) removetimer{    [Self.timer invalidate];     // so empty the Self.timer    . Self.timer = Nil;}

2> use the Proxy method to resolve issue 1. When you are about to drag, remove the timer. Complete drag and drop is the start timer.

#pragma mark-Proxy Method-(void) scrollviewwillbegindragging: (Uiscrollview *) scrollview{     // 1. Stop the timer, once the timer stops, it cannot be reused.     [self removetimer];} -(void) scrollviewdidenddragging: (Uiscrollview *) ScrollView willdecelerate: (BOOL) decelerate{     //  start timer     [self addtimer];}

Resolve Issue 2:

Method 1> Multithreading. It's not working here. Events that handle UI interfaces in iOS can only be executed in the main thread and cannot be processed with other threads. If more than one thread handles the UI interface. It is likely to cause confusion. For example, the UI displays a copy of the data. To ensure that only one person can modify this data at the same time. If you have multiple threads, you can have more than one person working at the same time. It's going to clash.

Method 2> increase the priority of the ScrollView drag event, which is to let the main thread handle both events at the same time.

[[Nsrunloop Currentrunloop] AddTimer:self.timer formode:nsrunloopcommonmodes];//Gets the message loop of the current main thread, Add the Self.timer to the main run loop. Nsrunloopcommonmodes can handle multiple events at the same time.

Bug fixes for Infinite carousel

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.