当设备旋转iPhone / iPad时,也会使子视图旋转 [英] Make subview rotate too when device is rotated iPhone/iPad
问题描述
当我说我想要旋转我的子视图时,让我解释一下我的意思。我放了很多图像让我自己清楚。这可能看起来很多,但事实并非如此。只是想清楚。
Let me explain what I mean when I say that I want to rotate my subview too. I placed a lot of images to make my self clear. This may look like to much but it is not. Just wanted to be clear.
在我目前正在处理的nib文件中,我有一个UIView和按钮。
In the nib file that I am currently working on, I have a UIView and button.
我在界面中创建的UIView builder与名为ViewMain的IBOutlet相关联:
The UIView that I created in interface builder is connected with the IBOutlet named ViewMain:
按钮执行以下方法:
and the button executes the following method:
该方法的作用是将视图放置在我在界面中创建的UIView控制器中的另一个nib文件中建设者。我实际放置的nib文件是:
and what that method does is that it places the view from another nib file in the UIView controller that I created in interface builder. The nib file that I am actually placing is:
我只是放置随机控件以更好地说明我的观点。
I just placed random controls to illustrate better my point.
所以到目前为止一切都很棒(当用户按下按钮时,来自另一个ViewController的视图出现在ViewMain上)
so everything so far is great (the view from anotherViewController shows up on ViewMain when the user presses the button)
一切看起来很棒但是注意什么时候发生什么我旋转我的设备:
EVERYTHING LOOKS GREAT BUT NOTE WHAT HAPPENS WHEN I ROTATE MY DEVICE:
我希望我的子视图(anotherViewController.view)也可以进行评估。我不介意它是否比ViewMain更大,因为我可以有一个透明的背景。我只需要旋转它。我怎么能这样做?
I would like my subview (anotherViewController.view) to ratate as well. I don't mind if it is bigger than ViewMain because I can have a transparent background. I just need to rotate it as well. How can I do that?
推荐答案
定义 shouldAutorotateToInterfaceOrientation:
在你 UIViewController
这样它总是返回YES:
Define shouldAutorotateToInterfaceOrientation:
in you UIViewController
so that it always returns YES:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
看这里了解更多详情。
您还应该注意正确定义视图和子视图的自动调整行为,以便在自动旋转时一切正常。
You should also take care to correctly define the autoresizing behavior of your view and subviews, so that everything is fine when autorotating.
编辑:
在Interface Builder中设置视图的autoresize属性,选择视图,然后转到Info窗口中的View Size窗格并设置自动调整如下图所示。
to set the autoresize property for a view in Interface Builder, select the view then go to the "View Size" pane in the Info window and set "Autosizing" as in the image below.
这篇关于当设备旋转iPhone / iPad时,也会使子视图旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!