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)