苹果建议为iOS4和更高版本(here)使用UIView动画块,但是我非常喜欢带有kCATransitionPush效果的旧CATransition。如何使用UIView动画实现kCATransitionPush?我只在可用选项中看到四种类型的 View 过渡(向左/向右翻转,向上/向下 curl )

如果我自己实现,则计划创建一个新 View 并在滑入旧 View 的同时将其滑入。我不明白为什么Apple在UIView动画中不包含“推”效果。

谢谢!

狮子座

最佳答案

通过阅读您发布的Apple文档,它似乎还说:



我认为这是因为他们建议使用,因为大大简化了动画的创建。它还指出,它不能与任何没有ios 4的设备一起使用。如果您知道如何使用CAAnimation,我会继续使用它。我仍然没有任何问题地使用它:

- (void)switchTwoViews:(UIView *)view1 otherView:(UIView *)view2 direction:(int)directionRL{
view2.frame = CGRectMake(0, 0, 400, 211);
visibleView = view2;
// remove the current view and replace with view1
[view1 removeFromSuperview];
[currentOptionsView addSubview:view2];

// set up an animation for the transition between the views
CATransition *animation = [CATransition animation];
[animation setDuration:0.3];
[animation setType:kCATransitionPush];
if (directionRL == 0) {
    [animation setSubtype:kCATransitionFromRight];
} else {
    [animation setSubtype:kCATransitionFromLeft];
}

[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

[[currentOptionsView layer] addAnimation:animation forKey:@"SwitchToView"];

}

10-07 19:41
查看更多