Reason :
There may be many possibilities to this problem.
1) If your view's viewController
is a subView
of some other rootViewController
which is not a navigationController
, then there might be chances that rotation call is not propagating to the subView's controller.
2) Somewhere I read that if Super
methods are not called properly where it is needed then it might be the cause of rotation problem, which means that all ViewControllers in view stack which are related to the autorotation must call the super
methods in method implementations (i.e. calling [super viewDidLoad]
from the ViewController's viewDidLoad
).
You can use below trick to handle orientation changes.
Register a notifier in viewWillAppear.
-(void)viewWillAppear:(BOOL)animated{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];}
The orientation change will notify the below function.
- (void)orientationChanged:(NSNotification *)notification{
[self handleOrientation:[[UIApplication sharedApplication] statusBarOrientation]];}
which will call the below method where you can handle the orientation changes.
- (void) handleOrientation:(UIInterfaceOrientation) orientation {
if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown)
{
//handle the portrait view
}
else if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
{
//handle the landscape view
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…