不鼓励使用beginAnimations [英] Use of beginAnimations discouraged

查看:947
本文介绍了不鼓励使用beginAnimations的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

meronix最近通知我,不鼓励使用 beginAnimations 。通过 UIView 类引用阅读我看到这确实是真的 - 根据Apple类参考:

I was informed recently by meronix that use of beginAnimations is discouraged. Reading through the UIView class reference I see that this is indeed true - according to the Apple class ref:


在iOS 4.0及更高版本中不鼓励使用此方法。您应该使用
基于块的动画方法来指定您的动画。

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(希望如此)但最终可能会被弃用/删除。

I see that a large number of other methods - which I use frequently - are also "discouraged" which means they'll be around for iOS 6 (hopefully) but probably will be deprecated/removed eventually.

为什么不鼓励使用这些方法?

作为附注,右边现在我在所有类型的应用程序中使用 beginAnimations ,最常见的是在显示键盘时移动视图。

As a side note, right now I'm using beginAnimations in all sorts of apps, most commonly to move the view up when a keyboard is shown.

//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];
    }
}

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

Not sure how to duplicate this functionality with block-based methods; a tutorial link would be nice.

推荐答案

他们不鼓励因为有更好,更清洁的选择

They are discouraged because there is a better, cleaner alternative

在这种情况下,所有块动画都会在开始和提交调用中自动换行动画更改(例如 setCenter:),这样你就不会忘记。它还提供了一个完成块,这意味着您不必处理委托方法。

In this case all a block animation does is automatically wrap your animation changes (setCenter: for example) in begin and commit calls so you dont forget. It also provides a completion block, which means you don't have to deal with delegate methods.

Apple的文档非常好,但作为一个例子,要做块形式的相同动画将是

Apple's documentation on this is very good but as an example, to do the same animation in block form it would be

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

此外,ray wenderlich在块动画上有一个很好的帖子:链接

Also ray wenderlich has a good post on block animations: link

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

Another way is to think about a possible implementation of block animations

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

这篇关于不鼓励使用beginAnimations的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆