[英]What's the point of iOS 6 - (BOOL) shouldAutorotate?
As far as I know the correct practice on iOS 6 is to write a code like this to handle autorotation: 据我所知,iOS 6上的正确做法是编写这样的代码来处理自动旋转:
// iOS 6
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
Instead of writing 而不是写作
// pre-iOS 6 support
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
BOOL retVal = UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
return retVal;
}
To be honest, I think that the pre-iOS 6 is much more clear: I don't understand the point of having 2 methods to handle autorotation, specially because I've seen -(BOOL) shouldAutorotate
returning YES
in all the examples. 说实话,我认为iOS 6之前的版本要清楚得多:我不明白有两种方法可以处理自动旋转,特别是因为我看过-(BOOL) shouldAutorotate
在所有例子中都返回YES
。 Am I missing something? 我错过了什么吗?
The new API lets you save a call to get the current device orientation: the two questions, namely 新API允许您保存呼叫以获取当前设备方向:两个问题,即
are most often answered statically, without making a call to check the current orientation. 通常是静态回答,而不是打电话来检查当前的方向。 The savings become more important when a screen has multiple views controlled by separate view controllers. 当屏幕具有由不同视图控制器控制的多个视图时,节省变得更加重要。
Since the iOS is making a call into your app's shouldAutorotate
in response to an event from the accelerometer, it already knows the new orientation; 由于iOS正在调用应用程序的shouldAutorotate
来响应加速度计的事件,因此它已经知道新的方向; if your app answers 'YES`, the iOS could then check the current orientation against the list of supported ones, and come up with a decision without your app querying for the current orientation. 如果你的应用回答'是',那么iOS可以根据支持的列表检查当前方向,并在没有你的应用查询当前方向的情况下做出决定。
In the unlikely case that your app needs to decide on auto-rotation based on the new orientation, the new API is no worse than the old one, so it's a "win-draw" situation. 在不太可能的情况下,您的应用需要根据新的方向决定自动轮换,新的API并不比旧的API差,所以这是一个“胜利”的情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.