objective-c – 不鼓励使用beginAnimment

最近我被meronix通知使用beginAnimations是不鼓励的.通过UIView类参考阅读我看到这是真的 – 根据苹果类ref:

Use of this method is discouraged in iOS 4.0 and later. You should use
the block-based animation methods to specify your animations instead.

我看到大量的其他方法 – 我经常使用的 – 也是“不鼓励”,这意味着他们将在iOS 6(希望),但可能最终将被弃用/删除.

为什么这些方法不鼓励?

作为附注,现在我在各种应用程序中使用beginAnimations,最常见的是在显示键盘时移动视图.

//Pushes the view up if one of the table forms is selected for editing
- (void) keyboardDidShow:(NSNotification *)aNotification
{
    if ([isRaised boolValue] == NO)
    {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.25];
        self.view.center = CGPointMake(self.view.center.x,self.view.center.y-moveAmount);
        [UIView commitAnimations];
        isRaised = [NSNumber numberWithBool:YES];
    }
}

不确定如何使用基于块的方法来复制此功能;教程链接会很好

解决方法

因为有一个更好,更干净的选择,他们是不鼓励的

在这种情况下,所有块动画都会自动将您的动画更改(例如setCenter)封装在开始和提交调用中,以便您不要忘记.它还提供了一个完成块,这意味着你不必处理委托方法.

苹果公司的文档非常好,但作为一个例子,以块的形式做同样的动画

[UIView animateWithDuration:0.25 animations:^{
    self.view.center = CGPointMake(self.view.center.x,self.view.center.y-moveAmount);
} completion:^(BOOL finished){
}];

还有ray wenderlich有一个很好的帖子块动画:link

另一种方法是考虑块动画的可能实现

+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations
{
    [UIView beginAnimations];
    [UIView setAnimationDuration:duration];
    animations();
    [UIView commitAnimations];
}

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...