How to make one UIView in a fixed position, while all others autorotate?

I am trying to create a user interface with a UINavigationController that represents some UIViewController with a child UIViewController as a sidebar. In landscape orientation, it should be a strip on the right side. When rotating to a portrait, it should remain on that physical side, while the UINavigationController autorotates everything else with it. Thus, in portrait orientation, the side panel becomes a bottleneck.

Look at the layout, please. User interface layout

Now how to do it? Return NO for shouldAutorotateToInterfaceOrientation:interfaceOrientation: does not stop the rotation of this sidebar: - /

+4
source share
4 answers

Change the frame and / or view transformation in the autorotation detection method of the view controller, something like this:

 - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)to duration:(NSTimeInterval)duration { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:duration]; // Calculate the new frame and rotation angle of the view // eg: if (UIInterfaceOrientationIsPortrait(to)) { theView.frame = CGRectMake(0, 924, 768, 100); theView.transform = CGAffineTransformIdentity; } else { theView.frame = CGRectMake(924, 0, 100, 768); theView.transform = CGAffineTransformMakeRotation(M_PI / 2); } [UIView commitAnimations]; } 
+2
source
 CGAffineTransform t; //You have to caculate the angel of view controller rotating CGFloat rotateAngel = M_PI / 2;//replace 'M_PI / 2' with your view controllers rotation angel t = CGAffineTransformMakeRotation(-rotateAngel); [view setTransform:t]; 
+1
source

Is it possible to separate the side view from the view of the navigation controller (do not make it a child). This way you have more control over the rotation. Anyway, you can rotate the images inside the view.

+1
source

You cannot use automatic rotation for this, since on one screen you mixed two view controllers. Turn off automatic rotation on both the parent and child controllers, and do the necessary transformations yourself when you detect a turn. Auto-rotate will rotate all views in the controller view (including the subtitle controlled by your other view controller).

Alternatively, you can first shift the view (when you get willRotateToInterfaceOrientation) and then bring it back in the correct orientation when you get didRotateFromInterfaceOrientation.

+1
source

All Articles