[英]How can I fix the webpage orientation to Portrait only for iPad and iPhone?
[英]How can I query the current orientation of an iPhone/iPad screen?
我很想知道是否有辦法確定iPhone / iPad上的屏幕方向。
目前我發現自己在調用此消息時設置了一個成員變量:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
self.orientation = interfaceOrientation;
return YES;
}
...感覺像我應該能夠查詢狀態,而不是在它發生變化時跟蹤它。
UIViewController具有interfaceOrientation屬性。
不要對UIDevice中的方向感到困惑,因為UIDevice不是界面的方向,而是物理方向。
如果您的狀態欄位於頂部,請使用此選項。
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
// portrait
} else {
// landscape
}
你可以做[[UIDevice currentDevice] orientation]
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.