Issues encountered with IOS carousel (pause, restart)

Source: Internet
Author: User

First, the optimization of the carousel or the use of collection to achieve

Second, the Timer problem

We can use a timer like this.

[Nstimer scheduledtimerwithtimeinterval:1.0 target:self selector: @selector (function:) Userinfo:nil repeats : NO];

This is a timer that executes once and does not repeat

But in most cases, the timer we need is always going to have to execute D

Here is an extension of the timer inside the Carousel control:

@implementationNstimer (addition)-(void) pausetimer{if(![self isValid]) {        return ; } [self setfiredate:[nsdate distantfuture];}-(void) resumetimer{if(![self isValid]) {        return ; } [self setfiredate:[nsdate date];}- (void) Resumetimeraftertimeinterval: (nstimeinterval) interval{if(![self isValid]) {        return ; } [self setfiredate:[nsdate datewithtimeintervalsincenow:interval];}@end

//setfiredate:[nsdate Distantfuture], you can let the timer temporarily sleep, sleep, young man.//setfiredate:[nsdate Date], this will give the timer a fresh glow, Start running again

The last one is how long it takes to run again after the delay.

Sometimes when we switch to another place in the interface, we need to stop the switch on the carousel, actually let the timer hibernate, we can do this:

-(void) viewwillappear: (BOOL) animated{    [Super viewwillappear:animated];    [_mbannerscrollview Resumetimer];} -(void) viewwilldisappear: (BOOL) animated{    [Super viewwilldisappear:animated];    [_mbannerscrollview Pausetimer];}

When the interface is not visible, let the timer stop, when the interface is visible, the timer resumes normal operation.

Finally, the problem is the release of the timer.

[Timer invalidate];timer = nil;

This allows a timer to be released to prevent the timer from running after my view is set to nil.

Issues encountered with IOS carousel (pause, restart)

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.