[UIViewtransitionWithView...] 和 [UIViewtransitionFromView...] 之间的区别
我当前有一个包含在视图中的视图。主视图控制器(父视图)有一个属性,该属性在界面构建器中连接到子视图。子视图包含一个按钮。我希望按钮翻转子视图,同时保持主视图静止。目前,我的 IBAction 中有以下用于该按钮的代码:
[UIView transitionWithView: self.subViewFront
duration: 1.0
options: UIViewAnimationOptionTransitionFlipFromTop
animations: nil
completion: nil];
[UIView commitAnimations];
[[self view] addSubview: self.subViewBack;
该代码效果很好,但是在查看 Apple 的 API 参考时我注意到以下内容:
在 iOS 4 及更高版本中不鼓励使用本节中的方法。 请改用基于块的动画方法。
按照这个建议,我尝试使用以下代码:
[UIView transitionFromView: self.subViewFront
toView: self.subViewBack
duration: 1.0
options: UIViewAnimationOptionTransitionFlipFromTop
completion: nil];
它看起来应该与我最初编码的内容相同,但是,当我使用此代码运行我的应用程序时,它会翻转我的整个视图(父视图和子视图),而不仅仅是子视图。是否应该使用此方法来替代我使用的原始方法,或者我缺少什么?谢谢。
I currently have a view that is contained on a view. The main view controller (parent view) has a property that is hooked up in interface builder to the subview. The subview contains a button. I want the button to flip the subview while keeping the main view stationary. I currently have the following code in my IBAction for the button:
[UIView transitionWithView: self.subViewFront
duration: 1.0
options: UIViewAnimationOptionTransitionFlipFromTop
animations: nil
completion: nil];
[UIView commitAnimations];
[[self view] addSubview: self.subViewBack;
This code works great, however I noticed the following when looking at the API reference from Apple:
Use of the methods in this section is discouraged in iOS 4 and later.
Use the block-based animation methods instead.
Following this advice I attempted to use the following code:
[UIView transitionFromView: self.subViewFront
toView: self.subViewBack
duration: 1.0
options: UIViewAnimationOptionTransitionFlipFromTop
completion: nil];
It looks like it should do the same as what I originally coded, however, when I run my app with this code, it flips my entire view (parent and child view) instead of just the subview. Should this method be used as a substitution from the original method I have used, or is there something I'm missing? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了同样的问题(父级变得动画),但通过将两个视图(
subViewFront
和subViewBack
)添加到容器视图来解决它。因此,将两个视图添加到容器
UIView
中,然后使用-transitionFromView:...
就像您的示例所示:I had the same issue (with the parent getting animated instead), but resolved it by adding the two views (
subViewFront
andsubViewBack
) to a container view instead.So add your two views to a container
UIView
instead, then use the-transitionFromView:...
just like your example says: