【问题标题】:How can I exclude a piece of code inside a core animation block from being animated?如何将核心动画块内的一段代码排除在动画之外?
【发布时间】:2009-05-27 10:11:15
【问题描述】:

我有一个核心动画块,我在其中调用将加载视图控制器的方法。两个视图控制器之间发生了自定义转换。然而,当视图控制器构建界面时,所有这些东西都会受到核心动画的影响。虽然它会产生一些有趣的效果,但我不希望这样;)

[UIView beginAnimations:@"jump to view controller" context:self];
[UIView setAnimationDuration:0.55];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

// some animated property-changes here...

[self loadViewControllerForIndex:targetIndex]; // everything that happens in this method shall not be animated

UIViewController *controller = [viewControllers objectAtIndex:targetIndex];
[controller viewWillAppear:YES];
[controller viewDidAppear:YES];

[UIView commitAnimations];

很遗憾,我无法将那部分移出街区。

【问题讨论】:

    标签: iphone cocoa-touch uikit core-animation


    【解决方案1】:

    您应该能够通过将 UIView 动画块的一部分包装在 CATransaction 中并为其禁用动画来抑制该部分的动画:

    [CATransaction begin];
    [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];    
    
    // Changes to disable animation for here
    [CATransaction commit];
    

    【讨论】:

    • 这不是和动画块中的 +[CATransaction setDisableActions:YES] 一样吗?
    • @Andrew - 是的,-setDisableActions: 是在 iPhone OS 3.0 和 Snow Leopard 中添加的,与我上面使用的 -setValue:forKey: 相同。我是从我在 2.0 中使用的一些旧代码中获取的。
    • 这对我很有效,谢谢分享。此外,它比其他人在此处发布的 [UIView setAnimationsEnabled: NO] 方法要好(显然昨晚已删除)。因为这种方法只是关闭了 all 动画,包括调用者可能为自己设置的动画。
    • 还有一个基于块的替代方案[UIView performWithoutAnimations:(void (^)(void))actionsWithoutAnimation]。从 iOS7 开始可用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-21
    • 2011-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多