background image

return CGAffineTransformIdentity;
}

5.可以动画的改变我们 view 的显示方式了
[[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationLandscapeRight 
animated:YES];

CGFloat duration = [UIApplication sharedApplication].statusBarOrientationAnimationDuration;
(获取当前电池条动画改变的时间)
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:duration];

//在这里设置 view.transform 需要匹配的旋转角度的大小就可以了。

[UIView commitAnimations];

第二种:通过 setOrientation:的办法强制性的旋转到一个特定的方向。

注意:Apple 在 3.0 以后都不支持这个办法了,这个办法已经成为了私有的了,但是要跳
过 App Stroe 的审核,需要一点巧妙的办法。

不要直接调用[[UIDevice currentDevice] setOrientation: UIInterfaceOrientationLandscapeRight]
这样的办法来强制性的横屏,这样导致你的程序是很难通过 App Store 审核的。但是你可
以选择使用 performSelector 的办法来调用它。具体就几行代码如下:

//强制横屏
if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
[[UIDevice currentDevice] performSelector:@selector(setOrientation:)
withObject:(id)UIInterfaceOrientationLandscapeRight];
}

总结:

 

如果第一种办法可以满足你需要的话,最好使用第一种办法,因为那个上 App Store

肯定没问问题,但是第二种的话是需要冒风险的,但是如果你的结构太复杂了,导致使

 

用第一种办法人为很难控制的话,可以尝试简单的使用第二种办 法。我在有米提供的
sample 里面就看到他使用了第二种简单的办法来显示横屏竖式的广告条。