Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 7 Interface Orientation

Tags:

ios

I have an app that is always showed in portrait mode.

But in somewhere i have a media gallery that must support landscape.

The supported orientation by default in the project is portrait. Because of that the gallery is only showed in portrait mode.

If i change the project setting to show in portrait and landscape the gallery works fine but i can't control the other viewControllers to show only in portrait.

I tried several methods like shouldAutoRotate but no one worked.

Any ideia how to solve?

Regards

EDIT:

Solved :)

First i configured the project to support all orientation. Then i added this method to the AppDelegate.m:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscape;
}

After this what i did was to block orientation in each view controller, less the one i want to have orientation in landscape and portrait.

Code to block orientation (iOS 7):

- (BOOL)shouldAutorotate
{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return (UIInterfaceOrientationMaskPortrait);
}

Thanks to everyone that answered me :)

like image 842
Miguel Chaves Avatar asked Dec 06 '13 11:12

Miguel Chaves


1 Answers

In my app for iPhone its only support the portrait view only, but as per requirement need to support landscape view only for on view, at that time I use following way and its help me :

In your app delegate .h

@interface PlayWithWSWithLibAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {

       BOOL flagOrientationAll;
}

@property (assign) BOOL flagOrientationAll;

Add following method in your app delegate .m file

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
    //NSLog(@"PlayWithWSWithLibAppDelegate -- supportedInterfaceOrientationsForWindow");
    if([UICommonUtils isiPad]){
        return UIInterfaceOrientationMaskAll;
    }else if(flagOrientationAll == YES){
        return UIInterfaceOrientationMaskAll;
    } else {
        return UIInterfaceOrientationMaskPortrait;
    }
}

Implement following way in your view which you want to rotate in both portrait and landscape both for iPhone device

-(void)viewWillAppear:(BOOL)animated
{
    self.tabBarController.delegate = self;

    PlayWithWSWithLibAppDelegate *delegate = (PlayWithWSWithLibAppDelegate *) [[UIApplication sharedApplication] delegate];
    delegate.flagOrientationAll = YES;
 }
}

-(void)viewWillDisappear:(BOOL)animated
{
    //NSLog(@"viewWillDisappear -- Start");
     PlayWithWSWithLibAppDelegate *delegate = (PlayWithWSWithLibAppDelegate *)[[UIApplication sharedApplication] delegate];
        delegate.flagOrientationAll = NO;
}

see this post also: How to set one of the screens in landscape mode in iphone?

like image 179
Divya Bhaloidiya Avatar answered Oct 07 '22 16:10

Divya Bhaloidiya