自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

iOS橫豎屏解決方案

移動開發(fā) iOS
ios橫豎屏的效果是不相同的,所以我們在開發(fā)中如果允許屏幕橫豎屏間的切換,那么我們就要調(diào)整視圖的布局。利用Interface Builder開發(fā),我們可以快速的拖拽出合適的界面布局。

ios橫豎屏的效果是不相同的,所以我們在開發(fā)中如果允許屏幕橫豎屏間的切換,那么我們就要調(diào)整視圖的布局。利用Interface Builder開發(fā),我們可以快速的拖拽出合適的界面布局,但是屏幕自動切換布局不能很好的適配,下圖是,沒有做任何調(diào)整的狀態(tài)下,實現(xiàn)的橫豎屏切換,可以看到界面不是很美觀。

image39.pngimage40.png

目前我所知的實現(xiàn)ios橫豎屏切換的解決方案共有三種:

1.利用Interface Builder適配器自動適配調(diào)整界面。

2.在橫豎屏切換時,每個控件重新布局。

3.利用Interface Builder創(chuàng)建兩個視圖,橫屏?xí)r切換到橫屏視圖,豎屏?xí)r切換到豎屏視圖。

在ios中,橫豎屏切換時,會調(diào)用下面函數(shù):

  1. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
  2.         if (interfaceOrientation==UIInterfaceOrientationLandscapeLeft) { 
  3.             //zuo 
  4.         } 
  5.         if (interfaceOrientation==UIInterfaceOrientationLandscapeRight) { 
  6.             //you 
  7.         } 
  8.         if (interfaceOrientation==UIInterfaceOrientationPortrait) { 
  9.             //shang 
  10.         } 
  11.         if (interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown) { 
  12.             //xia 
  13.         } 
  14.         return YES; 
  15.     } 
  16.   

返回yes表示切換屏幕,返回no是不能向相應(yīng)的方向切換視圖。

下面分別介紹一下三種方法,***種方法最簡單,但是效果是最差的,我們只需用Interface bulider修改相應(yīng)的屬性即可。實現(xiàn)的效果如下:
image41.pngimage42.png

實現(xiàn)的方法:

image43.png

選中控件,按command+3,上圖紅框部分的紅線表示距離不能自動適配,要是虛線表示距離可以自動適配。我們選擇可以自動適配,***的結(jié)果就如上圖。

第二種方法:

第二種方法是相應(yīng)的控件和代碼相關(guān)聯(lián):

代碼:

  1. @interface ipad_demooViewController : UIViewController { 
  2.  
  3.        IBOutlet UIButton *myButton1; 
  4.         IBOutlet UIButton *myButton2; 
  5.         IBOutlet UIButton *myButton3; 
  6.         IBOutlet UIButton *myButton4; 
  7.         IBOutlet UIButton *myButton5; 
  8.         IBOutlet UIButton *myButton6; 
  9.     } 
  10.     @property (nonatomic,retain) UIButton *myButton1; 
  11.     @property (nonatomic,retain) UIButton *myButton2; 
  12.     @property (nonatomic,retain) UIButton *myButton3; 
  13.     @property (nonatomic,retain) UIButton *myButton4; 
  14.     @property (nonatomic,retain) UIButton *myButton5; 
  15.     @property (nonatomic,retain) UIButton *myButton6; 
  16.  
  17.     @end 
  18.   

和IB相關(guān)聯(lián):

更改每一個控件的布局:

  1. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
  2.        if (interfaceOrientation==UIInterfaceOrientationLandscapeLeft) { 
  3.            //zuo 
  4.            self.myButton1.frame=CGRectMake(86, 208, 72, 37); 
  5.            self.myButton2.frame=CGRectMake(480, 208, 72, 37); 
  6.            self.myButton3.frame=CGRectMake(86, 308, 72, 37); 
  7.            self.myButton4.frame=CGRectMake(480, 308, 72, 37); 
  8.            self.myButton5.frame=CGRectMake(86, 408, 72, 37); 
  9.            self.myButton6.frame=CGRectMake(480, 408, 72, 37); 
  10.        } 
  11.        if (interfaceOrientation==UIInterfaceOrientationLandscapeRight) { 
  12.            //you 
  13.            self.myButton1.frame=CGRectMake(86, 208, 72, 37); 
  14.            self.myButton2.frame=CGRectMake(480, 208, 72, 37); 
  15.            self.myButton3.frame=CGRectMake(86, 308, 72, 37); 
  16.            self.myButton4.frame=CGRectMake(480, 308, 72, 37); 
  17.            self.myButton5.frame=CGRectMake(86, 408, 72, 37); 
  18.            self.myButton6.frame=CGRectMake(480, 408, 72, 37); 
  19.        } 
  20.        if (interfaceOrientation==UIInterfaceOrientationPortrait) { 
  21.            //shang 
  22.            self.myButton1.frame=CGRectMake(86, 208, 72, 37); 
  23.            self.myButton2.frame=CGRectMake(480, 208, 72, 37); 
  24.            self.myButton3.frame=CGRectMake(86, 308, 72, 37); 
  25.            self.myButton4.frame=CGRectMake(480, 308, 72, 37); 
  26.            self.myButton5.frame=CGRectMake(86, 408, 72, 37); 
  27.            self.myButton6.frame=CGRectMake(480, 408, 72, 37); 
  28.        } 
  29.        if (interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown) { 
  30.            //xia 
  31.            self.myButton1.frame=CGRectMake(86, 208, 72, 37); 
  32.            self.myButton2.frame=CGRectMake(480, 208, 72, 37); 
  33.            self.myButton3.frame=CGRectMake(86, 308, 72, 37); 
  34.            self.myButton4.frame=CGRectMake(480, 308, 72, 37); 
  35.            self.myButton5.frame=CGRectMake(86, 408, 72, 37); 
  36.            self.myButton6.frame=CGRectMake(480, 408, 72, 37); 
  37.        } 
  38.        return YES; 
  39.    } 

第三種方法是創(chuàng)建兩個視圖,下面看一下實現(xiàn)過程:

首先創(chuàng)建兩個視圖:

  1. IBOutlet UIView *hView; 
  2. IBOutlet UIView *vView; 
  3.   

創(chuàng)建相應(yīng)的@property方法.

然后在IB中在復(fù)制一個view。

image44.png

把一個視圖做橫屏?xí)r的布局,一個view做豎屏?xí)r的布局。把相應(yīng)的view和相應(yīng)的方法相連接,在設(shè)置一個默認視圖為view。

下面就是代碼實現(xiàn):

  1. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
  2.         if (interfaceOrientation==UIInterfaceOrientationLandscapeLeft) { 
  3.             //zuo 
  4.             self.view=self.hView; 
  5.            } 
  6.         if (interfaceOrientation==UIInterfaceOrientationLandscapeRight) { 
  7.             //you 
  8.             self.view=self.hView; 
  9.           } 
  10.         if (interfaceOrientation==UIInterfaceOrientationPortrait) { 
  11.             //shang 
  12.             self.view=self.vView; 
  13.            } 
  14.         if (interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown) { 
  15.             //xia 
  16.             self.view=self.vView; 
  17.           } 
  18.         return YES; 
  19.     } 
  20.   

實現(xiàn)的效果如下:

image45.pngimage46.png

上述就是我目前知道的三種橫豎屏解決方案,我們可以看到第三種比較簡單,但是編寫比較麻煩,實現(xiàn)復(fù)雜邏輯比較麻煩,第二種方法實現(xiàn)起來不直觀,調(diào)試比較麻煩,但是效果***。

源代碼:http://easymorse-iphone.googlecode.com/svn/trunk/ipad.demoo/

ios6.0橫豎屏切換問題解決

this class is not key value coding-compliant for the key

ios5里面的旋轉(zhuǎn)方法ios6里面確實掉不到了,但是還是可以用的。

首先,在app的主界面(也就是自己的主ViewController.m)里面加上

  1. -(NSUInteger)supportedInterfaceOrientations{ 
  2.     return UIInterfaceOrientationMaskAllButUpsideDown;//這里返回哪個值,就看你想支持那幾個方向了。這里必須和后面plist文件里面的一致(我感覺是這樣的)。 
  3.  
  4. - (BOOL)shouldAutorotate { 
  5.     return YES;//支持轉(zhuǎn)屏 
  6.   

這兩個函數(shù)。

然后在plist文件里面找到Supported interface orientations (iPad)選項,添加你想支持的方向,都有提示的。

然后問題就解決了。

也許我描述的還有問題,希望你能指正。謝謝了。

  1. -(NSUInteger)supportedInterfaceOrientations{ 
  2.     return UIInterfaceOrientationMaskAllButUpsideDown;//這里返回哪個值,就看你想支持那幾個方向了。這里必須和后面plist文件里面的一致(我感覺是這樣的)。 
  3.   

這里的設(shè)置會覆蓋掉plist中的值

還有需要注意:mainViewController要設(shè)置為window的rootViewController,addSubView上去可能存在問題。并且上面的所有subViewController都會受到rootViewController支持朝向的影響

責(zé)任編輯:張葉青 來源: eoe Android開發(fā)者社區(qū)
相關(guān)推薦

2011-07-29 10:21:03

iPad 橫豎屏 切換

2017-12-26 14:05:21

潤乾大屏可視化

2017-07-25 09:55:10

iOS橫豎屏旋轉(zhuǎn)

2009-12-22 15:50:11

2020-02-05 11:20:39

微軟瀏覽器Windows

2018-12-03 12:13:21

Mellanox解決方案

2018-12-03 12:26:30

YADRO解決方案

2018-12-03 11:59:42

Inventec解決方案

2012-05-27 16:21:31

IDC華為

2018-12-03 12:17:27

Semptian解決方案

2013-05-23 10:51:28

Android開發(fā)移動開發(fā)橫豎屏切換

2016-03-13 17:58:57

2023-07-10 16:06:50

鴻蒙檢測鎖屏應(yīng)用

2011-08-03 09:44:18

IOS開發(fā) UITextFiel UITableVie

2011-04-08 09:13:13

游戲跨平臺iOS

2016-03-13 17:35:18

2010-12-24 12:51:36

2011-05-05 15:36:25

深信服廣域網(wǎng)加速

2012-05-28 13:30:00

華為SmartCDN

2009-03-05 10:38:00

點贊
收藏

51CTO技術(shù)棧公眾號