1

In my app, all view is opening in Portait mode, But I want to change the mode for AVPlayer view, means When user come on this view, device orientation is automatically change in to Landscape mode.

I have implemented this using following code. It works fine, I want to just confirm, by using following code, there will be any problem when I upload my app on appstore.

-(void)viewDidAppear:(BOOL)animated
{
    if(UIDeviceOrientationIsPortrait(self.interfaceOrientation)){
        if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)])
        {
            objc_msgSend([UIDevice currentDevice], @selector(setOrientation:), UIInterfaceOrientationLandscapeLeft );
        }
    }
}


-(void)viewDidDisappear:(BOOL)animated{

    if(UIDeviceOrientationIsLandscape(self.interfaceOrientation)){
        if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)])
        {
            objc_msgSend([UIDevice currentDevice], @selector(setOrientation:), UIInterfaceOrientationPortrait );
        }
    }
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
KDRocks
  • 161
  • 3
  • 18

1 Answers1

0

Here you can find a brief discussion on the similar issue. Non of them worked for me. Here is my work around.

-(BOOL)shouldAutorotate
{
    return true;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationLandscapeLeft |
           UIInterfaceOrientationLandscapeRight;
}

-(void) setSelfOrientation
{
    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
    [self shouldAutorotate];

     self.view.transform = CGAffineTransformIdentity;
     self.view.transform = CGAffineTransformMakeRotation(M_PI_2);
    [self.view setFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.height, 
                     [[UIScreen mainScreen] bounds].size.width)];
}

-(void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];

    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait]; // rollback previous orientation
    [self shouldAutorotate];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    [self setSelfOrientation];
}
Community
  • 1
  • 1
NeverHopeless
  • 11,077
  • 4
  • 35
  • 56
  • If you want you can transform the view with UIView animation as well. – NeverHopeless Mar 26 '14 at 08:18
  • By using your code my view is rotate in landscape mode, But my Navigation bar is not rotate and status bar is also in Portait mode , When I change device orientation in landscape mode then View is not rotate properly . – KDRocks Mar 26 '14 at 09:24
  • Basically , View is rotate in landscape mode when iphone is in portait mode by using above code .Please help me – KDRocks Mar 26 '14 at 09:25
  • You need to set your navigation controller code as well. Please visit the link as well. – NeverHopeless Mar 26 '14 at 10:31