Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
724 views
in Technique[技术] by (71.8m points)

objective c - 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.

In the nib file that I am currently working on, I have a UIView and button.

enter image description here

The UIView that I created in interface builder is connected with the IBOutlet named ViewMain:

enter image description here

and the button executes the following method: enter image description here

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:

enter image description here

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)

enter image description here

enter image description here

EVERYTHING LOOKS GREAT BUT NOTE WHAT HAPPENS WHEN I ROTATE MY DEVICE:

enter image description here

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...