gpt4 book ai didi

iphone - 使用UIView动画从CATransition实现kCATransitionPush

转载 作者:可可西里 更新时间:2023-11-01 05:24:44 25 4
gpt4 key购买 nike

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

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

谢谢!

狮子座

最佳答案

从阅读您发布的苹果文档来看,它似乎还说:

The block-based animation methods (such as animateWithDuration:animations:) greatly simplify the creation of animations. With one method call, you specify the animations to be performed and the options for the animation. However, block-based animations are available only in iOS 4 and later. If your application runs on earlier versions of iOS, you must use the beginAnimations:context: and commitAnimations class methods to mark the beginning and ending of your animations.

我认为这意味着他们推荐它因为它极大地简化了动画的创建。它还指出,它不适用于任何没有 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"];

关于iphone - 使用UIView动画从CATransition实现kCATransitionPush,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6805634/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com