先上效果图
两种方案
1 使用两个view,依次滚动来实现,并在滚动结束后回到原来位置
2 使用一个view,在一个view上添加转场动画,今天我们使用这个方案实现,
核心逻辑代码
CATransition *transition = [CATransition animation];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromTop;
transition.duration = 1;
CAMediaTimingFunction *function = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
transition.timingFunction = function;
self.index ++;
if (self.index >= self.titlearray.count - 1) {
self.index = 0;
}
NSString *title = self.titlearray[self.index];
[self.button setTitle:title forState:UIControlStateNormal];
[self.button.layer addAnimation:transition forKey:@"move"];