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!