让我解释一下当我说我也想旋转我的子视图时我的意思。我放了很多图片来让自己清楚。这可能看起来很像,但事实并非如此。只是想澄清一下。
在我当前正在处理的 nib 文件中,我有一个 UIView 和按钮。
我在界面生成器中创建的 UIView 与名为 ViewMain 的 IBOutlet 连接:
按钮执行以下方法:
该方法的作用是将另一个 nib 文件中的视图放置在我创建的 UIView 控制器中在界面生成器中。我实际放置的 nib 文件是:
我只是放置了随机控件来更好地说明我的观点。
所以到目前为止一切都很棒(当用户按下按钮时,来自 anotherViewController 的视图显示在 ViewMain 上)
一切看起来都很棒,但请注意旋转时会发生什么我的设备:
我希望我的子视图 (anotherViewController.view) 也能进行评级。我不介意它是否比 ViewMain 大,因为我可以有透明的背景。我也只需要旋转它。我怎样才能做到这一点?
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.
In the nib file that I am currently working on, I have a UIView and button.
The UIView that I created in interface builder is connected with the IBOutlet named ViewMain:
and the button executes the following method:
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.
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:
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?
发布评论
评论(1)
在
UIViewController
中定义shouldAutorotateToInterfaceOrientation:
,使其始终返回 YES:查看 此处了解更多详细信息。
您还应该注意正确定义视图和子视图的自动调整大小行为,以便自动旋转时一切正常。
编辑:
要在 Interface Builder 中设置视图的自动调整大小属性,请选择该视图,然后转到信息窗口中的“视图大小”窗格并设置“自动调整大小”,如下图所示。
Define
shouldAutorotateToInterfaceOrientation:
in youUIViewController
so that it always returns YES:Look here for more details.
You should also take care to correctly define the autoresizing behavior of your view and subviews, so that everything is fine when autorotating.
EDIT:
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.