成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

iOS橫豎屏解決方案

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

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

image39.pngimage40.png

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

1.利用Interface Builder適配器自動適配調整界面。

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

3.利用Interface Builder創建兩個視圖,橫屏時切換到橫屏視圖,豎屏時切換到豎屏視圖。

在ios中,橫豎屏切換時,會調用下面函數:

  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是不能向相應的方向切換視圖。

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

實現的方法:

image43.png

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

第二種方法:

第二種方法是相應的控件和代碼相關聯:

代碼:

  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相關聯:

更改每一個控件的布局:

  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.    } 

第三種方法是創建兩個視圖,下面看一下實現過程:

首先創建兩個視圖:

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

創建相應的@property方法.

然后在IB中在復制一個view。

image44.png

把一個視圖做橫屏時的布局,一個view做豎屏時的布局。把相應的view和相應的方法相連接,在設置一個默認視圖為view。

下面就是代碼實現:

  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.   

實現的效果如下:

image45.pngimage46.png

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

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

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

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

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

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

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

這兩個函數。

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

然后問題就解決了。

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

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

這里的設置會覆蓋掉plist中的值

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

責任編輯:張葉青 來源: eoe Android開發者社區
相關推薦

2011-07-29 10:21:03

iPad 橫豎屏 切換

2017-12-26 14:05:21

潤乾大屏可視化

2017-07-25 09:55:10

iOS橫豎屏旋轉

2018-12-03 12:17:27

Semptian解決方案

2012-05-27 16:21:31

IDC華為

2013-05-23 10:51:28

Android開發移動開發橫豎屏切換

2009-12-22 15:50:11

2018-12-03 11:59:42

Inventec解決方案

2018-12-03 12:13:21

Mellanox解決方案

2018-12-03 12:26:30

YADRO解決方案

2020-02-05 11:20:39

微軟瀏覽器Windows

2016-03-13 17:58:57

2023-07-10 16:06:50

鴻蒙檢測鎖屏應用

2009-07-15 17:09:32

Swing線程

2010-12-21 17:28:58

2010-12-21 17:39:59

2012-05-27 17:01:36

華為云教育數據

2018-12-03 12:23:45

IBMMCM解決方案

2017-08-02 17:23:22

AzureIoTAWS

2018-12-03 12:04:10

Kyligence解決方案
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 亚洲精品电影网在线观看 | 天天躁日日躁性色aⅴ电影 免费在线观看成年人视频 国产欧美精品 | 国产色视频网站 | 欧美黄色片 | 国产毛片av | 国产一二区视频 | 国产精品亚洲成在人线 | 欧美性网 | 在线观看免费福利 | 亚洲三级av | 精品日韩一区 | 国产一区在线看 | av手机在线免费观看 | 日韩精品免费播放 | 国产情侣在线看 | 久在线视频播放免费视频 | 狠狠躁天天躁夜夜躁婷婷老牛影视 | 免费不卡av | 久久久精品网站 | 久久精品国产一区二区电影 | 日韩欧美国产精品 | 日本电影一区二区 | 久久精品中文字幕 | 精品一区二区在线观看 | 亚洲视频在线看 | 中国一级大毛片 | 国产目拍亚洲精品99久久精品 | 国产精品一码二码三码在线 | 国内精品视频一区二区三区 | 国产精品久久久久久亚洲调教 | 草久视频 | 午夜小视频在线播放 | 欧美日韩久| 91精品国产综合久久久久久 | 久久久久一区二区三区 | 日韩一区二区三区在线视频 | 国产福利91精品 | 日韩视频在线一区 | 超碰成人在线观看 | 麻豆a级片 | 中文字幕日韩欧美一区二区三区 |