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

首頁 > 學院 > 開發(fā)設計 > 正文

iPad橫屏模式研究

2019-11-14 20:14:30
字體:
供稿:網(wǎng)友

ipad應用開發(fā)時如何讓設備只支持橫屏(landscape)模式,我做了多次嘗試,并沒有發(fā)現(xiàn)比較簡捷的設置方法。我嘗試了大概大概3種方式。 
1、通過XCode設置“iPad Deployment info”,只選擇橫屏左和橫屏右,部署測試后并沒有生效,這種方法實質(zhì)是在xxx_info.plist項目配置文件中添加如下信息: 
<key>UISupportedInterfaceOrientations~ipad</key> 
<array> 
<string>UIInterfaceOrientationLandscapeLeft</string> 
<string>UIInterfaceOrientationLandscapeRight</string> 
</array> 
2、通過對每個nib文件在IB中設置orientation為landscape,此法也不生效。 
3、重載shouldAutorotateToInterfaceOrientation:方法,這種方式是可行的。具體如下: 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
return ((interfaceOrientation ==UIDeviceOrientationLandscapeLeft)||(interfaceOrientation ==UIDeviceOrientationLandscapeRight)); 
} 
如果第一種方式生效,那么比較完美。雖然第三種方式可以完全滿足橫屏的需求,但是實現(xiàn)起來比較stupid,需要在每個controller中都重載shouldAutorotateToInterfaceOrientation:方法,當然也可以通過擴展UIViewController的方式來避免重復勞動。但是感覺也有點不太直接,期待有人指出sdk本身是否就有簡捷方式支持。 

iPad的界面布局好多時候都要做兩套------橫屏和豎屏,但在界面切換時,該讓哪個布局顯示就要判斷了,有多種方法,我記錄下我用的一種,感覺比較方便: 
          NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; //Get the notification centre for the app 
    [nc addObserver:self //Add yourself as an observer 
           selector:@selector(orientationChanged) 
               name:UIDeviceOrientationDidChangeNotification 
             object:nil];//這個函數(shù)用來獲取當前設備的方向, 
- (void)orientationChanged 
{ 
    //UIView *ftView = [self.view viewWithTag:200]; 
    if([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft || [[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)//判斷左右 
    { 
         //界面的新布局 
    } 
    if([[UIDevice currentDevice] orientation] == UIInterfaceOrientationPortrait )//我有個方向不支持,如果想都支持那就不要這個if條件就行了 
    { 
         //界面的新布局 
    } 
} 

iOS 5 上真機測試過了。很方便,用過后才能體會到,這里不多說了!


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 馆陶县| 鄂温| 桐城市| 大兴区| 潍坊市| 巴里| 阳曲县| 桓仁| 麻江县| 阳山县| 安陆市| 平塘县| 平昌县| 临朐县| 札达县| 金坛市| 泾源县| 荥阳市| 库伦旗| 万宁市| 辽宁省| 铜川市| 嘉义市| 武夷山市| 图木舒克市| 湘阴县| 璧山县| 福海县| 和顺县| 克什克腾旗| 奉新县| 鄂尔多斯市| 洞口县| 敖汉旗| 博爱县| 平江县| 友谊县| 左权县| 拉萨市| 高阳县| 邓州市|