Reputation: 81
"Portrait" is the only supported interface orientation in app's info.plist and I can not change it;
But I need to auto rotate a specific view controller;
I can not find a way to do this easily, the only way I can find is to rotate every view, text and remake all constraints while receiving the device rotate notification, but I really do not want to this.
Is there any easier way to implement this?
Upvotes: 2
Views: 280
Reputation: 205
Try this method in AppDelegate.m
call from particular view controller where you want to make rotation enable.
self.fullScreenVideoIsPlaying
is bool set YES
for that particular view controller to make rotation enable
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
if (self.fullScreenVideoIsPlaying == YES){
return UIInterfaceOrientationMaskLandscapeLeft;
}else{
return UIInterfaceOrientationMaskPortrait;
}
}
Upvotes: 1
Reputation: 4451
Important Points:
If you want Rotation in Single OR more Screens so you have to enable it for throughout the application
. After enabling it from Target -> General -> Device Orientation you have to manage on specific view controller in which you want rotations.
For this you have to Do Following:
Check all the Device Rotation
mask in your application. Target -> General -> Device Orientation.
SubClass
you Navigation Controller
and write below code:
- (BOOL)shouldAutorotate{
//NSLog(@"%d",[[[self viewControllers] lastObject] shouldAutorotate]);
return [[[self viewControllers] lastObject] shouldAutorotate];
}
- (NSUInteger)supportedInterfaceOrientations{
// NSLog(@"%lu",(unsigned long)[[[self viewControllers] lastObject] supportedInterfaceOrientations]);
return [[[self viewControllers] lastObject] supportedInterfaceOrientations];
}
Return YES in all View Controllers in which you want to Rotate and No in which you dont want to roatate.
-(BOOL)shouldAutorotate
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
Upvotes: 1
Reputation: 997
Use this method in your controller which you want to rotate
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}
Upvotes: 0