[英]how to force interfaceOrientation programmatically on iPhone?
如何強制它僅顯示在UIDeviceOrientationPortrait上?
UIInterfaceOrientationLandscapeLeft上顯示的示例layer1
當我將ViewController推送到layer2時,它將自動顯示在UIInterfaceOrientationLandscapeLeft上,如何強制其顯示UIDeviceOrientationPortrait?
只需在視圖控制器中實現shouldAutorotateToInterfaceOrientation:
。
將以下內容放入您的layer2 viewController中:
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
我遇到了麻煩。 設置shouldAutorotateToInterfaceOrientation:可以將viewControllers推入堆棧將導致其視圖正確定向,但是您不能通過顯式函數調用將方向強制為縱向或橫向。
到目前為止,我所看到的最好的方法是自己處理動畫(使用CATransform和相關的CoreAnimation調用)。 不好看
如果有人知道強制視圖旋轉的方法(即不推/彈出視圖控制器,也不旋轉實際設備),請告訴我們。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.