[英]iOS how to stop view rotate
我希望我的iPad應用程序在您旋轉iPad時停止旋轉。 我想停止旋轉每個視圖。
有什么建議嗎?
如果要停止整個應用程序的旋轉,則只需在應用程序info.plist文件中更改支持的界面方向 , 初始界面方向屬性為縱向還是橫向取決於您
在iOS6 shouldAutorotateToInterfaceOrientation
,應該不建議使用AutorotateToInterfaceOrientation。 改寫同時supportedInterfaceOrientations
supportInterfaceOrientations和preferredInterfaceOrientationForPresentation
。
只需檢查視圖控制器的自動調整大小屬性即可。
(已修復語法錯誤)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if(interfaceOrientation == UIInterfaceOrientationPortrait)
return YES;
return NO;
}
全局可控旋轉鎖定的主要思想是編寫包含每個視圖控制器的鎖定機制的UIViewController類別。
您只需要全局修改supportedInterfaceOrientations
方法
- (NSUInteger)supportedInterfaceOrientations
{
return __orientation;
}
這里__orientation
是可以通過類別方法設置的靜態變量。
此處提供了類別的完整實現
請像這樣更新您的projectname.plist。 支持的界面方向只有一個對象“縱向(底部主頁按鈕)”
我強烈建議不要在iPad上停止旋轉,因為在iPad上必須支持旋轉。 這是因為iPad不像iPhone那樣具有正常的握持方式,而iPhone通常以縱向(AKA垂直)方式握持。 因此,您必須將選擇權留給用戶以最終鎖定方向
HIG實際上並未將其聲明為要求,但作為建議,但是有許多應用程序被此問題拒絕。
順便說一句,如果您想為視圖控制器的數量限制,則應實現:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if(interfaceOrientation == UIInterfaceOrientationPortrait){
return YES;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.