加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

objective-c – 不鼓励使用beginAnimment

发布时间:2020-12-16 03:22:29 所属栏目:百科 来源:网络整理
导读:最近我被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 inst
最近我被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];
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读