如何为 UIViewAnimation 定义多个选项?

发布于 2024-09-14 15:28:41 字数 812 浏览 6 评论 0原文

可能这只是一个正确语法的问题。

我使用 animateWithDuration:delay:options:animations:completion: UIView 方法。

options: 是这里有问题的部分:当我仅分配一个选项(例如 UIViewAnimationOptionCurveEaseInOut)时,一切正常。

如果我想为同一个动画分配多个选项怎么办?我怎样才能做到这一点?

我尝试了以下代码,但 options: 部分结果被完全忽略

>   [UIView animateWithDuration:DURATION
>                         delay:DELAY
>                       options:(UIViewAnimationOptionAllowUserInteraction,
>                                UIViewAnimationOptionCurveEaseInOut)
>                    animations: ^{/*animations here*/}
>                    completion: ^(BOOL finished){/*actions on complete*/}];

这只是一次尝试,但没有成功。我应该在这里使用哪种语法?

感谢您提前提供的任何帮助。

Probably it is just a question of proper syntax.

I use the animateWithDuration:delay:options:animations:completion: UIView method.

The options: is the problematic part here: when I assign only one option (for example UIViewAnimationOptionCurveEaseInOut) everything works fine.

What if I want to assign multiple options to the same animation? How can I do that?

I have tried the following code, but the options: part turned out to be completely ignored:

>   [UIView animateWithDuration:DURATION
>                         delay:DELAY
>                       options:(UIViewAnimationOptionAllowUserInteraction,
>                                UIViewAnimationOptionCurveEaseInOut)
>                    animations: ^{/*animations here*/}
>                    completion: ^(BOOL finished){/*actions on complete*/}];

It was just a try and it didn't work. Which syntax should I use here?

Thanks for any help in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

反目相谮 2024-09-21 15:28:41

Objective-C

options:(UIViewAnimationOptionAllowUserInteraction |
                            UIViewAnimationOptionCurveEaseInOut)

Swift

在 Swift UIViewAnimationOptions 中是一个 选项集类型和多个选项可以通过以下方式传递:

options:[.AllowUserInteraction, .CurveEaseInOut]

Objective-C

options:(UIViewAnimationOptionAllowUserInteraction |
                            UIViewAnimationOptionCurveEaseInOut)

Swift

In Swift UIViewAnimationOptions is an Option set type and multiple options can be passed following way:

options:[.AllowUserInteraction, .CurveEaseInOut]
长伴 2024-09-21 15:28:41

只是补充一下编译器似乎忽略了您提供的选项但没有抛出错误的原因是因为您尝试的语法使用了在 C 中经常被忽视的逗号运算符。本质上

(UIViewAnimationOptionAllowUserInteraction, UIViewAnimationOptionCurveEaseInOut)

告诉编译器放弃第一个选项并仅分配逗号后面的值。在更一般的情况下,将对逗号运算符的第一个参数进行求值,但其结果将被丢弃。

Just to add the reason it seems the compiler ignored your supplied options yet didn't throw an error is because the syntax that you tried makes use of the comma operator which is often overlooked in C. Essentially

(UIViewAnimationOptionAllowUserInteraction, UIViewAnimationOptionCurveEaseInOut)

tels the compiler to discard the first option and only assign the value after the comma. In the more general case, the first argument to the comma operator is evaluated, but it's result is discarded.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文