最近做了個支持iphone和ipad的小應(yīng)用柳恐,被橫豎屏切換搞得有點難受伐脖,這里做一下總結(jié)。
1乐设、在info.plist文件中做橫豎屏的設(shè)置
一般在info.plist文件中有這兩個屬性(Supported interface orientations)讼庇、(Supported interface orientations (iPad))
這兩個屬性是設(shè)置橫豎屏相關(guān)的,對應(yīng)的是一個數(shù)組
如果不想橫屏近尚,只設(shè)置一個item蠕啄,設(shè)置為(Portrait (bottom home button))就好了,如果需要橫屏戈锻,可以選擇其他選項
也可以轉(zhuǎn)換為source code編輯歼跟,
UISupportedInterfaceOrientations
UIInterfaceOrientationPortrait
UISupportedInterfaceOrientations~ipad
UIInterfaceOrientationPortrait
UIInterfaceOrientationPortraitUpsideDown
2、重載ViewController的shouldAutorotateToInterfaceOrientation方法
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return ((interfaceOrientation ==UIDeviceOrientationPortrait)||(interfaceOrientation ==UIDeviceOrientationPortraitUpsideDown));
}