2 starwar2012 starwar2012 于 2013.07.03 15:25 提问

修改iPhone通用程序的方向

我想要开发的程序能适应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;
     }
}

但是不能停在横向模式。

1个回答

lanhailvcao
lanhailvcao   2013.07.03 16:04
已采纳

在iPhoneSummary设置中禁用所有方向,除了 UIInterfaceOrientationPortraitUIInterfaceOrientationPortraitUpsideDown。如下图:

CSDN移动问答

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!