效果图
原理
就是持有两个视图,并且两个视图同时改变origin.y
动画结束之后,判断哪个视图是在上面并且看不到的,
则将该视图移动到底部,并且该视图展示下一跳内容
在开始下一轮动画
代码
- (void)startAnimationWithDuration:(CGFloat)duration
{
self.duration = duration;
[self changeAnimation];
}
- (void)changeAnimation
{
CGRect rect1 = self.label1.frame;
CGPoint point1 = rect1.origin;
point1.y -= CGRectGetHeight(self.bounds);
rect1.origin = point1;
CGRect rect2 = self.label2.frame;
CGPoint point2 = rect2.origin;
point2.y -= CGRectGetHeight(self.bounds);
rect2.origin = point2;
self.currentIndex = (self.currentIndex + 1)%self.titleArray.count;
NSString *crrentTitle = self.titleArray[self.currentIndex];
[UIView animateWithDuration:0.5 animations:^{
self.label1.frame = rect1;
self.label2.frame = rect2;
} completion:^(BOOL finished) {
if (CGRectGetMinY(self.label1.frame) < - CGRectGetHeight(self.bounds) / 2) {
self.label1.frame = self.bottomRect;
self.label1.text = crrentTitle;
} else {
self.label2.frame = self.bottomRect;
self.label2.text = crrentTitle;
}
}];
[self performSelector:@selector(changeAnimation) withObject:nil afterDelay:3.5];
}
demo
如果对你有帮助,请给一个star