2
我想要做相同的應用程序:它看起來像只有肖像模式是支持的,但是當你旋轉某些視圖時旋轉,而工具欄和一些控件在同一個地方。相機應用程序支持的方向?
我試圖在PLIST文件中禁用所有支持的方向,但是這不會調用shouldRotate等委託方法,或者顯然,willRotate會執行方向更改。
當支持方向在PLIST中時,即使我爲shouldRotate方法返回NO,iPhone也會旋轉所有視圖。
如何解決這種困境?
我想要做相同的應用程序:它看起來像只有肖像模式是支持的,但是當你旋轉某些視圖時旋轉,而工具欄和一些控件在同一個地方。相機應用程序支持的方向?
我試圖在PLIST文件中禁用所有支持的方向,但是這不會調用shouldRotate等委託方法,或者顯然,willRotate會執行方向更改。
當支持方向在PLIST中時,即使我爲shouldRotate方法返回NO,iPhone也會旋轉所有視圖。
如何解決這種困境?
在info.plist
中,將唯一支持的方向設置爲Portrait
。然後,在你viewDidLoad
方法,添加:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];
這將調用方法:
- (void)didRotate:(NSNotification *)aNotification; {
UIDeviceOrientation currentDeviceOrientation = [[UIDevice currentDevice] orientation];
switch(currentDeviceOrientation){
case UIDeviceOrientationPortrait:
break;
case UIDeviceOrientationPortraitUpsideDown:
break;
case UIDeviceOrientationLandscapeLeft:
break;
case UIDeviceOrientationLandscapeRight:
break;
default:
break;
}
}
從那裏,你可以做基於任何選項,任何你想要的。另外,不要忘了添加:
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
給你dealloc方法。希望有助於!
謝謝,我會試試看。 – Vad