成人免费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華為

2009-12-22 15:50:11

2020-02-05 11:20:39

微軟瀏覽器Windows

2018-12-03 11:59:42

Inventec解決方案

2018-12-03 12:26:30

YADRO解決方案

2018-12-03 12:13:21

Mellanox解決方案

2013-05-23 10:51:28

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

2016-03-13 17:58:57

2023-07-10 16:06:50

鴻蒙檢測鎖屏應用

2011-08-03 09:44:18

IOS開發 UITextFiel UITableVie

2011-04-08 09:13:13

游戲跨平臺iOS

2009-07-15 17:09:32

Swing線程

2010-12-21 17:28:58

2012-05-27 17:01:36

華為云教育數據

2018-12-03 12:23:45

IBMMCM解決方案

2017-08-02 17:23:22

AzureIoTAWS
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 日韩看片| 亚洲精品高清视频 | 福利片一区二区 | 欧美精品成人影院 | 黄色成人免费在线观看 | 精品自拍视频 | 国产 日韩 欧美 制服 另类 | 人人艹人人 | 黑人巨大精品欧美黑白配亚洲 | 一本一道久久a久久精品蜜桃 | 欧美一区免费 | 欧美日韩一区二区在线观看 | 国产日韩一区二区三免费 | 国产免费一级一级 | 成人国产精品入口免费视频 | 91av视频在线 | jlzzjlzz欧美大全 | 91精品国产一区二区三区动漫 | 日韩二| 久久久久国产一级毛片高清网站 | 免费av直接看 | 久久久久成人精品亚洲国产 | 欧美精品一区二区三区四区 在线 | 在线视频一区二区三区 | 欧美黄页 | 精品国产乱码久久久久久蜜臀 | 成人激情视频在线 | 久久av.com | 97成人免费 | 国产精品国产三级国产aⅴ中文 | 亚洲97| 天天干com | 亚洲欧美日韩高清 | 亚洲精品久久视频 | 在线播放中文字幕 | 亚洲高清视频在线 | 亚洲狠狠爱 | 日韩中文字幕一区 | 午夜电影福利 | 久久精品成人一区 | 国产污视频在线 |