我想要開發的程序能適應iPad所有方向,在iPhone中只要UIInterfaceOrientationPortrait 和UIInterfaceOrientationPortraitUpsideDown這兩個。代碼如下:
-(BOOL)shouldAutorotate {
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
return NO;
}else{
return YES;
}
}
- (NSUInteger)supportedInterfaceOrientations{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
return UIInterfaceOrientationMaskPortrait;
}else{
return UIInterfaceOrientationMaskAll;
}
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
return interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown ;
}else{
return YES;
}
}
但是不能停在橫向模式。
在iPhoneSummary設置中禁用所有方向,除了 UIInterfaceOrientationPortrait
和UIInterfaceOrientationPortraitUpsideDown
。如下圖: