I have been developing an app which requires orientation only for one view, for which I require a way to detect the current view in the appdelegate page
Can anyone please help and tell me how this is possible
Regards,
Neha
I have been developing an app which requires orientation only for one view, for which I require a way to detect the current view in the appdelegate page
Can anyone please help and tell me how this is possible
Regards,
Neha
You can specify the app's supported orientations here:
If you select only Portrait
then you essentially lock your app in the Portrait mode
If you want all your viewController
s to be locked in Portrait
mode but allow multiple orientations to a single/selected viewController
(s) then you could implement this quick fix:
In the viewController
that allows multiple orientations:
-(void)viewWillAppear:(BOOL)animated
{
[[NSUserDefaults standardUserDefaults] setObject:@(YES)
forKey:@"allowLandscape"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
-(void)viewWillDisappear:(BOOL)animated
{
[[NSUserDefaults standardUserDefaults] setObject:@(NO)
forKey:@"allowLandscape"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
In your AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//...
//default setting when app starts
[[NSUserDefaults standardUserDefaults] setObject:@(NO)
forKey:@"allowLandscape"];
[[NSUserDefaults standardUserDefaults] synchronize];
//...
}
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"allowLandscape"] boolValue]) {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
return UIInterfaceOrientationMaskPortrait;
}