0

how to force it show on UIDeviceOrientationPortrait only?

example layer1 display on UIInterfaceOrientationLandscapeLeft

when i pushViewController to layer2 it will auto show on UIInterfaceOrientationLandscapeLeft how can i force it to display UIDeviceOrientationPortrait?

RAGOpoR
  • 8,118
  • 19
  • 64
  • 97

3 Answers3

2

Simply implement shouldAutorotateToInterfaceOrientation: in your view controller.

Stefan Arentz
  • 34,311
  • 8
  • 67
  • 88
1

Put the following in your layer2 viewController:

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
mahboudz
  • 39,196
  • 16
  • 97
  • 124
0

I've had trouble with this. Setting shouldAutorotateToInterfaceOrientation: makes it so that pushing viewControllers onto a stack will result in their views being oriented properly, but you can't force an orientation to portrait or landscape with an explicit function call.

The best I've seen so far is to handle the animation yourself (with a CATransform and related CoreAnimation calls). It's not pretty.

If someone knows of a way to force the view to rotate (i.e. without pushing/popping view controllers, and without rotating the actual device) then please let me/us know.

David Carney
  • 2,200
  • 1
  • 19
  • 28