过渡动画
- (void)changeImage
{
[_imageView.layer removeAllAnimations];
CATransition *transition = [CATransition animation];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromRight;
[_imageView.layer addAnimation:transition forKey:nil];
_imageIndex = (_imageIndex >= self.animateArray.count -1) ? 0 : (_imageIndex + 1);
_imageView.image = [self.animateArray objectAtIndex:_imageIndex];
}
- (void)startTimer
{
[self invilateTimer];
__weak typeof(self) weakSelf = self;
_timer = [NSTimer scheduledTimerWithTimeInterval:0.5 repeats:YES block:^(NSTimer * _Nonnull timer) {
__strong typeof(weakSelf) strongSelf = weakSelf;
[strongSelf changeImage];
}];
}
- (void)invilateTimer
{
if (_timer)
{
[_timer invalidate];
_timer = nil;
}
}Last updated