简体   繁体   English

UIView在情节提要中切换风景和肖像场景的动画?

[英]UIView switching animation for landscape and portrait scene in storyboard?

I'm trying to design different layouts for my view controller. 我正在尝试为我的视图控制器设计不同的布局。 After googling, I've got this answer from SO. 谷歌搜索后,我从SO得到了这个答案。 Basically, the answer instructs me to setup 2 scenes, one for landscape and one for portrait, when the device rotates, hide one and show the other one. 基本上,答案指示我设置2个场景,当设备旋转时,一个场景用于风景,一个场景用于肖像,隐藏一个场景并显示另一个场景。

And my question is what if I want to add a sweet animation for the rotation process? 我的问题是,是否要为旋转过程添加漂亮的动画? For example, since I can setup the same view on different scenes, can I set the motion path for these views and disappear? 例如,由于我可以在不同的场景上设置相同的视图,因此可以为这些视图设置运动路径并消失吗? Or, if it is easier, can I add some rotation and fade out animation? 或者,如果更简单,是否可以添加一些旋转并淡出动画?

I'm quite green with Core Animation, so a detailed explanation is very useful for me. 我对Core Animation非常满意,因此详细的说明对我非常有用。 Big big thanks in advance! 提前大感谢!

There are a few options here. 这里有一些选择。 The main methods you are looking for to do any of this are: 您正在寻找的主要方法是:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 
                                duration:(NSTimeInterval)duration;

and

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;

If you want to move the elements around the screen while the rotation is happening you will be best off changing the frames of the elements rather than creating a separate view file. 如果要在旋转时在屏幕上移动元素,最好不要更改元素的框架,而要创建单独的视图文件。 Using any motion animation would require some mapping between the two and I have never heard of anything like this before. 使用任何运动动画都需要在两者之间进行一些映射,而我之前从未听说过这样的事情。 Again, if you just change the frames though, you can preform basically any screen movements you would like (for views and subviews). 同样,如果您只是更改框架,则基本上可以执行任何想要的屏幕移动(用于视图和子视图)。

To do the fading you could just throw an animation block in the first method: 要进行淡入淡出,您可以在第一种方法中抛出一个动画块:

[UIView animateWithDuration:duration 
                     animations:^{
    // set alphas for old and new views here.
}];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM