我正在编写一个应用程序,我希望根据方向显示不同的视图。例如,如果设备是纵向加载pView,如果横向加载lView。以下是我目前尝试的代码。
- (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 :(得分:1)
我发现以下2个(Apple)示例项目很有用:
http://developer.apple.com/library/ios/#samplecode/AlternateViews/Introduction/Intro.html
http://developer.apple.com/library/ios/#samplecode/WhichWayIsUp/Introduction/Intro.html
此外,请记住从设备的角度来看,还有面朝上和面朝下的方向;这让我感到高兴。
答案 1 :(得分:0)
我不得不问一个显而易见的问题:
您的iPad是否已开启屏幕方向锁定开关?
答案 2 :(得分:0)
根据您要执行的操作,您可以在IB中设置界面以自动处理旋转。您可以调整组件大小,移动图片和标签,这样的东西。这可能会做你想做的事情......