標籤:style http io ar os 使用 sp for on
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的橫豎顯示方式
關於設定iOS橫豎屏的兩種方式(轉載)