iOS 7 Interface Orientation

后端 未结 2 1877
北海茫月
北海茫月 2020-12-01 22:26

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 defau

相关标签:
2条回答
  • 2020-12-01 22:36

    You have to make another class in the same view Controller where you are presenting your media.

    In that you can specify your orientation where it will support only landscape orientation only when you will present your media.

    I am giving you an example of my app which supports only in landscape mode but as I took Image picker and it supports only in portrait mode so I changed the orientation for only that view.

    #pragma mark - Image PICKER
    
    @interface NonRotatingUIImagePickerController : UIImagePickerController
    
    @end
    
    @implementation NonRotatingUIImagePickerController
    
    
    
    - (BOOL)shouldAutorotate
    {
        return YES;
    }
    
    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
    {
        return UIInterfaceOrientationPortrait ;
    }
    
    @end
    

    Then when I used ImagePicker I used object of the class that i made.

    So I define like below.

    UIImagePickerController* picker = [[NonRotatingUIImagePickerController alloc] init];
    

    So For Image Picker It showed only in portrait mode.

    You just need to change Landscape instead of portrait if you want only Landscape Orientation for your particular view where you want to change it.

    Hope this helps you.

    0 讨论(0)
  • 2020-12-01 23:01

    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?

    0 讨论(0)
提交回复
热议问题