0
votes

Im having a modal view displayed on top of tab bar controller the orientation of tab bar controller and my modal view is currently in portrait mode, i need to only change my modal views orientation to landscape mode, i Tried usign UIDevice Orientation but no success it only works when .plist has UIDeviceOrientationKey, and i dont want whole of my application in landscape mode. secondly i even tried using UIApplication setStatusBarOrientation but my view doesn't respond to it i.e. only my device(simulator) get rotated but the view still remains in portrait mode, using affine transformation on UIView creates an empty view my view is created through XIB.

Please Help

Thanks Rakesh

2

2 Answers

1
votes

I have used this and it works well with some tweaking.

0
votes

Until today I 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 wont accept new releases of my App due to _setRotatableViewOrientation:duration:transition:toView: isn't documented API.

So be aware for use it in your commercial projects! Apple new automated API checker will reject your App!