[英]Can I prevent mobile safari from auto-rotating the screen on ipod touch or iphone?
[英]iPhone UIActionSheet auto-rotating not working
我讀了很多關於這一點。 人們說它不會自動旋轉它的父母沒有設置為自動旋轉。 我嘗試了一切,但沒有運氣。 我用一個執行此操作的按鈕創建了基於視圖的應用程序(v4.2):
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Title" delegate:self cancelButtonTitle:@"Cancel Button" destructiveButtonTitle:@"Destructive Button" otherButtonTitles:@"Other Button 1", nil];
actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[actionSheet showInView:self.view];
根控制器設置為自動旋轉。 actionSheet沒有。 請注意,當我旋轉模擬器時,不會調用根控制器的方向方法。 代表有問題嗎? 怎么了?
好吧,這是我解決這個問題的方法:
基本上我們做的是:
例如:
@interface ViewController ()
{
UIActionSheet *_sheet;
BOOL _isClicked;
}
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];
}
- (IBAction)click:(id)sender
{
_isClicked = YES;
[self showActionSheet];
}
- (void)didRotate:(NSNotification *)note
{
[_sheet dismissWithClickedButtonIndex:1 animated:YES];
[self performSelector:@selector(showActionSheet) withObject:nil afterDelay:1.0];
}
- (void)showActionSheet
{
if (!_isClicked) return;
_sheet = [[UIActionSheet alloc] initWithTitle:@"title" delegate:self cancelButtonTitle:@"cancel" destructiveButtonTitle:@"new" otherButtonTitles:@"bla", nil];
[_sheet showInView:self.view];
}
當我從一個從屬視圖(我用導航控制器推動)的委托方法中呈現動作表時,我發現我遇到了這個問題。 問題是我的觀點不是現在的觀點,從屬觀點仍然在我試圖展示行動表的時候。
通過稍微更改我的代碼以使委托方法記錄用戶所需的交互,並將動作表演示推遲到此視圖的viewDidAppear方法,該表在適當的時間出現在邏輯界面動畫中,並且自動旋轉問題消失了。 您可能想看看它是否對您有所幫助。
換句話說,流程變為:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.