Change modal orientation of UIView in landscape mode on iPhone

Im having a modal view displayed on top of the tab bar controller, the orientation of the tab bar controller and my modal view is currently in portrait mode, I only need to change the orientation of the modal views to landscape mode, i Tried usign UIDevice Orientation but without success this only works then when .plist has UIDeviceOrientationKey and I don't want my whole app to be in landscape mode. secondly i even tried to use UIApplication setStatusBarOrientation but my view doesn't respond to it, i.e. only my device (simulator) is rotated but the view still stays in portrait mode using affine transformation on UIView creates empty view which my view created via XIB.

Please, help

Thanks Rahkesh

0


source to share


2 answers


I've used this one and it works well with some tweak.



+1


source


Until today, I have used the following solution:

-(void)setOrientation:(UIInterfaceOrientation)orientation
{
 SEL rotation = @selector(_setRotatableViewOrientation:duration:);
 NSMethodSignature * methodSignature = [window methodSignatureForSelector:rotation];
 if (methodSignature)
 {
  NSInvocation * ivc = [NSInvocation invocationWithMethodSignature:methodSignature];
  [ivc setTarget:window];
  [ivc setSelector:rotation];
  // arg0 will be self, 1 will be cmd_ (current method selector)
  [ivc setArgument:&orientation atIndex:2];
  double duration = 0.4;
  [ivc setArgument:&duration atIndex:3];
  [ivc invoke];
 }
}

-(void)normalizeOrientation
{
 UIDeviceOrientation dOrientation = [UIDevice currentDevice].orientation;

 int orientation = -1;

    switch(dOrientation)
    {
        case UIDeviceOrientationPortrait:
            orientation = UIInterfaceOrientationPortrait;
            break;
        case UIDeviceOrientationPortraitUpsideDown:
            orientation = UIInterfaceOrientationPortraitUpsideDown;
            break;
        case UIDeviceOrientationLandscapeRight:
            orientation = UIInterfaceOrientationLandscapeLeft;
            break;
        case UIDeviceOrientationLandscapeLeft:
            orientation = UIInterfaceOrientationLandscapeRight;
            break;
    }

    if (orientation != -1 && orientation != tabBarController.interfaceOrientation)
        [self setOrientation:orientation];
}

      



but the official AppStore won't accept new versions of my app due to _setRotatableViewOrientation: duration: transition: toView: API is not documented.

Know how to use it in your commercial projects! Apple's new automatic API check will reject your app!

0


source







All Articles