我正在编写一个应用程序,我想根据方向显示不同的视图。例如,如果设备是纵向加载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的。有任何想法吗?
不,我试图根据方向加载不同的视图。 – Tanner 2010-06-27 12:54:58