国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

關于設置iOS橫豎屏的兩種方式(轉載)

2019-11-14 19:48:54
字體:
來源:轉載
供稿:網友

iphone的橫屏豎屏針對iOS系統版本分為兩種開發方式: 一種是iOS 6之前的使用模式 一種是iOS6的新模式. 兩者的區別還是蠻大的.

1:iOS6之前通常使用 shouldAutorotateToInterfaceOrientation 來單獨控制某個UIViewController的方向,需要哪個viewController支持旋轉,只需要重寫shouldAutorotateToInterfaceOrientation方法。如下示例,設置以后,屏幕被旋轉時只支持橫屏轉換:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation  
{  
   return UIInterfaceOrientationIsLandscape(interfaceOrientation);  
}  
 
 
iOS6之后使用如下兩個方法控制自動旋轉,分別是:  
- (BOOL)shouldAutorotate  
{  
    NSLog(@"讓不讓我旋轉?");  
    return YES;  
}  
- (NSUInteger)supportedInterfaceOrientations {  
    NSLog(@"讓我旋轉哪些方向");  
    return UIInterfaceOrientationMaskAllButUpsideDown;  
}  
 
 
那么在自動旋轉觸發后,系統會自動調用另外兩個方法:  
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {  
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];  
    NSLog(@"將要旋轉了?");  
}  
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {  
    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];  
    NSLog(@"如果讓我旋轉,我已經旋轉完了!");       
}  
 
 
2:讓程序第一次啟動時立刻顯示橫屏還是豎屏的方式
如果是iOS6之前,下面設置的設備支持方向可在應用里面再被修改
如果是iOS6以后,會做為硬性條件,也就是如果設置了以后,應用里面的代碼也無法再使用這個方向
 
 
3:傳說中的私有API實現切換ViewController強制橫屏的方式
if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {  
        [[UIDevice currentDevice] performSelector:@selector(setOrientation:)  
                                       withObject:(id)UIInterfaceOrientationLandscapeRight];  
    }  
 
4:使用xib進行界面設計時,改變xib的橫豎顯示方式

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 平罗县| 祥云县| 昌乐县| 吉水县| 琼海市| 周口市| 沂水县| 新闻| 肥城市| 广灵县| 崇礼县| 武鸣县| 德格县| 库尔勒市| 壶关县| 忻城县| 浪卡子县| 湾仔区| 赤水市| 桂林市| 四平市| 张掖市| 射洪县| 益阳市| 奈曼旗| 罗平县| 樟树市| 东莞市| 巴里| 荔波县| 汉阴县| 德钦县| 邮箱| 肇庆市| 阿图什市| 山东省| 睢宁县| 原阳县| 山西省| 通许县| 西宁市|