如何为 UIViewAnimation 定义多个选项?
可能这只是一个正确语法的问题。
我使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Objective-C
Swift
在 Swift UIViewAnimationOptions 中是一个 选项集类型和多个选项可以通过以下方式传递:
Objective-C
Swift
In Swift UIViewAnimationOptions is an Option set type and multiple options can be passed following way:
只是补充一下编译器似乎忽略了您提供的选项但没有抛出错误的原因是因为您尝试的语法使用了在 C 中经常被忽视的逗号运算符。本质上
告诉编译器放弃第一个选项并仅分配逗号后面的值。在更一般的情况下,将对逗号运算符的第一个参数进行求值,但其结果将被丢弃。
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
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.