2010-06-26 36 views
0

我正在编写一个应用程序,我想根据方向显示不同的视图。例如,如果设备是纵向加载pView,如果横向加载lView。以下是目前试用的代码。iPad旋转,根据方向加载自定义视图的任何方式?

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation) 
interfaceOrientation duration:(NSTimeInterval)duration { 
if (interfaceOrientation == UIInterfaceOrientationPortrait) 
{ 
     self.view = portrait; 
} 
else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){ 
     self.view = portrait; 
} 
else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight){ 
     self.view = portrait; 
} 
else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft){ 
     self.view = landscape; 
} 

}

有了这个我已经建立在IB 2次以及连接在出口到右视图。香港专业教育学院也尝试过这样的:

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation) 
interfaceOrientation duration:(NSTimeInterval)duration { 
if (interfaceOrientation == UIInterfaceOrientationPortrait) 
{ 
     self.view = portrait; 
} 
else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){ 
     self.view = portrait; 
} 
else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight){ 
     lView *abo = [[lView alloc] initWithNibName:@"lView" bundle:nil]; 
     [self.navigationController pushViewController:abo animated:NO]; 
     [abo release]; 

} 
else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft){ 
     lView *abo = [[lView alloc] initWithNibName:@"lView" bundle:nil]; 
     [self.navigationController pushViewController:abo animated:NO]; 
     [abo release]; 

} 

}

的代码直接在上面工作了iPod,但没有ipad的。有任何想法吗?

回答

0

我要问一个明显的问题:

你有屏幕方向锁定开关开启你的iPad?

+0

不,我试图根据方向加载不同的视图。 – Tanner 2010-06-27 12:54:58

0

根据您要做的事情,您可以在IB中设置您的界面来自动处理旋转。您可以调整组件大小,移动图片和标签,等等。这可能会做你想做的事......

相关问题