iphone - 撤消或撤消kCATransitionPush以将图像发送到屏幕外

时间:2013-12-13 06:13:49

标签: ios iphone objective-c core-animation

我目前正在使用CATransition从屏幕右侧滑动动画图像:

CATransition *transition = [CATransition animation];
transition.duration = TRANSITION_DURATION;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromRight;
[self.layer addAnimation:transition forKey:nil];
self.image = [UIImage animatedImageNamed:prefix duration:ANIMATION_DURATION];

我的问题是,如何将图像滑出?一旦图像动画循环,我想将它从它出现的方向发送出屏幕,即TransitionToRight,但似乎没有这样的过渡类型。请建议我如何完成这种反向过渡。

如果存在这样的反向转换,我可以写它:

[self performSelector:@selector(removeAnimatedImage) withObject:nil afterDelay:ANIMATION_DURATION];

在removeAnimatedImage里面,我会用这个反方向创建另一个CATransition动画,将它从屏幕上发送出去。

2 个答案:

答案 0 :(得分:1)

您是否尝试过推送过渡的kCATransitionFromLeft版本?它应该是FromRight的反转。

答案 1 :(得分:0)

不是理想的解决方案,但一个黑客就是动画帧边界的变化,或者应用平移变换动画:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:TRANSITION_DURATION];

if (enteredFromRight) {
    self.transform = CGAffineTransformMakeTranslation(SCREEN_SPACE_WIDTH, 0);
} else {
    self.transform = CGAffineTransformMakeTranslation(-SCREEN_SPACE_WIDTH, 0);
}
[UIView commitAnimations];