最近作了個支持iphone和ipad的小應用,被橫豎屏切換搞得有點難受,這裏作一下總結。數組
一、在info.plist文件中作橫豎屏的設置iphone
通常在info.plist文件中有這兩個屬性(Supported interface orientations)、(Supported interface orientations (iPad))ide
這兩個屬性是設置橫豎屏相關的,對應的是一個數組code
若是不想橫屏,只設置一個item,設置爲(Portrait (bottom home button))就行了,若是須要橫屏,能夠選擇其餘選項ip
也能夠轉換爲source code編輯,string
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
</array>it
二、重載ViewController的shouldAutorotateToInterfaceOrientation方法io
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return ((interfaceOrientation ==UIDeviceOrientationPortrait)||(interfaceOrientation ==UIDeviceOrientationPortraitUpsideDown));
}
方法