[英]UIViewController container: allow different orientations for childs
更新:是否可以將一個UIViewController
( vc1
)作為容器並將一個UIViewController
作為子vc2
( vc2
)
[vs1 addChildViewController:vc2];
[vs1.view addSubview:vc2.view];
並允許vc2
方向更改獨立於vc1
支持的方向?
Fe vc1
僅支持縱向方向,而vc2
支持所有方向。 我想看到vc2
視圖旋轉為橫向,而vc1
視圖仍為縱向。
Fe我有VC1和VC2(彈出窗口)
VC1僅支持縱向方向,而VC2支持所有方向。
我想讓橫向顯示彈出窗口
方向由父視圖控制器檢測。 我使用的方法是在父視圖控制器中,檢測哪個視圖是當前活動視圖,然后根據該方向進行定向。
抱歉,標准行為無法實現您想要的。 當childViewController支持某個方向時,其父級和當前層次結構中的所有其他ViewController也必須支持該方向。
您應該做的是注冊parentViewController來接收設備旋轉通知,然后根據這些通知可以轉換childViewController的視圖。 因此,基本上,您的應用程序將始終保持縱向模式,但是childViewController的視圖將被轉換為看起來像是橫向的。
注冊設備定向通知,如下所示
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(deviceDidRotate:) name: UIDeviceOrientationDidChangeNotification object: nil];
然后這樣處理
// This method gets called everytime the device (!), not the viewController rotates
-(void)deviceDidRotate: (NSNotification*) notification
{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
// Animate the transform here based on the orientation
}
請記住,UIDeviceOrientation和UIInterfaceOrientation是相反的。 UIDeviceOrientationLandscapeLeft = UIInterfaceOrientationLandscapeRight。 該設備向左旋轉,因此用戶界面必須向右旋轉。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.