2013-11-10 27 views
0

我知道這個問題以前已經問過,但是Im還沒有找到解決方案。在Xcode 5中,我想將我的應用程序鎖定在右側。以下是我爲建立項目所採取的步驟。在ios7/Xcode 5中鎖定風景的方向

(1)創建一個單一的視圖項目

(2)一般設置選項卡下設置設備方向爲橫向右

(3)視圖控制器方向設定爲橫向main.storyboard

(4)下面的代碼添加到ViewController.m

-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{ 
    return interfaceOrientation == UIInterfaceOrientationLandscapeRight; 
} 

-(NSUInteger) supportedInterfaceOrientations{ 
    return UIInterfaceOrientationMaskLandscape; 
} 

- (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation{ 
    return UIInterfaceOrientationLandscapeRight; 
} 

(5)下面的代碼添加到的ViewController viewDidLoad中

NSLog(@"frame %f %f", self.view.frame.size.width, self.view.frame.size.height); 

我每次運行應用程序時我的看法是320×568

什麼我需要設置以獲得橫向視圖(568×320)。

謝謝。

+0

- (BOOL)shouldAutorotate {return YES;}也沒有效果。 – user2872885

回答

0

即使設備改變爲橫向模式的寬度和所述設備的高度/視圖將是相同的,並且它總是返回320×568

所不同的是用戶觀看裝置中的風景。它不會像你期望的那樣給你寬度和高度的變化。 !

+0

好的,當視圖顯然超過320寬時,這似乎很奇怪。 – user2872885

+0

再次,縱向和橫向的視圖高度保持不變,但如果需要在視圖中重新定位按鈕/控件,則視圖會有所不同,請使用自動調整大小 – Parthi