問題描述
我有一個 UIViewController
詳細視圖,它是從 UINavigationController
中的 UITableView
推送的.在 UIViewController
我添加了一些子視圖(例如 UITextView
、UIImageView
).
I have a UIViewController
detail view which is pushed from a UITableView
in a UINavigationController
. In the UIViewController
I add a number of subviews (e.g a UITextView
, UIImageView
).
在 iOS5
中,如果我的圖片視圖被放大,我使用此代碼停止自動旋轉(zhuǎn):
In iOS5
I used this code to stop autorotation if my picture view was enlarged :
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if (scrollView.isZoomed) {
return NO;
}
else {
return YES;
}
}
我正在嘗試在 iOS6
下使用:
I am trying to achieve the same thing under iOS6
using :
- (BOOL)shouldAutorotate {
return FALSE;
}
然而,這個方法永遠不會被調(diào)用,并且應用會繼續(xù)旋轉(zhuǎn).
However this method is never called and the app continues rotating.
誰能幫忙?
推薦答案
如果您有管理這些視圖的導航控制器,則不會調(diào)用 shouldAutorotate 方法.您必須繼承 UINavigationController 并覆蓋方法 shouldAutorotate 和 supportedIntervalOrientations.
If you have a Navigation Controller managing these views, the shouldAutorotate method won't be called. You would have to subclass UINavigationController and override methods shouldAutorotate and supportedIntervalOrientations.
來自文檔:
現(xiàn)在,iOS 容器(例如 UINavigationController)不會咨詢它們的子容器來確定它們是否應該自動旋轉(zhuǎn)
Now, iOS containers (such as UINavigationController) do not consult their children to determine whether they should autorotate
編輯-----
正如 Lomax 下面提到的,Apple 不鼓勵子類化 UINavigationController.您應該嘗試一個類別(this SO question解釋得很好):
As mentioned below by Lomax, subclassing UINavigationController is discouraged by Apple. You should try a category instead (this SO question explains it well):
@implementation UINavigationController
-(BOOL)shouldAutorotate
{
// your code
}
-(NSUInteger)supportedInterfaceOrientations
{
(...)
}
@end
這篇關(guān)于iOS6 中未調(diào)用 shouldAutoRotate 方法的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!