[英]Portrait in one viewController and landscape in another
我有以下ViewControllers:
InformationViewController和cardViewController。
我如何確保informationViewController處於縱向模式且不能旋轉。
那么cardViewController應該處於橫向模式並且不能旋轉。
我如何在每個viewController中實現這一點。 目前,我已經激活了protrait,一般在左右景觀
在informationViewController中:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
在cardViewController中:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscape);
}
看看我對這個問題的回答: 強制控制器以縱向或橫向更改其方向
(但是請不要使用不推薦使用的方法。有一些新方法可以使用。)
將視圖控制器限制為某些方向很容易。 但是,請參見有關如何強制設備實際旋轉的其他答案。 沒有這個技巧:如果在設備處於橫向時僅縱向視圖控制器變為可見,則無論您如何限制其支持的方向,它都將以橫向顯示。
在信息視圖控制器中
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
並在卡片視圖控制器中
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
注意:請確保在項目常規設置中在設備方向上勾選縱向和橫向模式(部署信息)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.