Make subview rotate too when device is rotated iPhone/iPad

末鹿安然 提交于 2019-12-29 07:05:45

问题


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:


Define shouldAutorotateToInterfaceOrientation: in you UIViewController so that it always returns YES:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
 {
    return 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.



来源:https://stackoverflow.com/questions/6654741/make-subview-rotate-too-when-device-is-rotated-iphone-ipad

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!