gpt4 book ai didi

objective-c - 不鼓励使用 beginAnimations

转载 作者:技术小花猫 更新时间:2023-10-29 10:59:32 25 4
gpt4 key购买 nike

我最近从 meronix 得知不鼓励使用 beginAnimations。阅读 UIView 类引用,我发现这确实是真的 - 根据 Apple 类引用:

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,最常见的是在显示键盘时向上移动 View 。

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

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

最佳答案

他们很沮丧,因为有更好、更清洁的选择

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

Apple 关于此的文档非常好,但作为示例,以 block 形式制作相同的动画

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

ray wenderlich 也有一篇关于 block 动画的好文章:link

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

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

关于objective-c - 不鼓励使用 beginAnimations,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11723545/

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