亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何只允許單個UIViewController沿橫向和縱向旋轉?

如何只允許單個UIViewController沿橫向和縱向旋轉?

iOS
滄海一幻覺 2019-12-13 15:10:08
我的應用僅適用于iphone設備(iphone 4和5),并且僅支持ios 6。我的整個應用僅支持portrait模式。但是有一個名為“ ChatView”的視圖,我想同時支持landscape和portrait模式。我已將所需的設備旋轉設置如下:我還嘗試了以下代碼來支持“ ChatView”中的旋轉--(BOOL)shouldAutorotate{    return YES;}-(NSUInteger)supportedInterfaceOrientations{    return UIInterfaceOrientationMaskLandscape;}但是它無法旋轉該視圖。我為此進行了很多搜索,但找不到我的問題的解決方案。而且在“ ChatView”中,還有一些對象,例如按鈕,文本字段,其框架是通過編程方式設置的。所以我想知道我是否還必須為橫向模式設置所有這些對象的框架?請幫我。謝謝.....
查看完整描述

3 回答

?
呼啦一陣風

TA貢獻1802條經驗 獲得超6個贊

簡單,但效果很好。iOS 7.1和8


AppDelegate.h


@property () BOOL restrictRotation;

AppDelegate.m


-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window

{

if(self.restrictRotation)

    return UIInterfaceOrientationMaskPortrait;

else

    return UIInterfaceOrientationMaskAll;

}

ViewController


-(void) restrictRotation:(BOOL) restriction

{

    AppDelegate* appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;

    appDelegate.restrictRotation = restriction;

}

viewDidLoad


[self restrictRotation:YES]; or NO



查看完整回答
反對 回復 2019-12-14
?
交互式愛情

TA貢獻1712條經驗 獲得超3個贊

您的視圖控制器將永遠不會旋轉到應用程序本身不支持的任何位置。您應該啟用所有可能的旋轉,然后在不應旋轉的視圖控制器中放入以下行


- (UIInterfaceOrientationMask)supportedInterfaceOrientations

{

    return UIInterfaceOrientationMaskPortrait;

}

在ChatView中,應為:


- (UIInterfaceOrientationMask)supportedInterfaceOrientations

{

    return UIInterfaceOrientationMaskAll;

}

如果您需要在輪換之后更改布局,則應對子視圖進行適當的更改


- (void)viewWillLayoutSubviews

使用self.view.bounds檢查的電流的大小view,因為self.view.frame旋轉后也不會改變。



查看完整回答
反對 回復 2019-12-14
  • 3 回答
  • 0 關注
  • 529 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號