Iphone iPad旋转,有没有基于方向加载自定义视图的方法?
我正在写一个应用程序,我想根据方向显示不同的视图。例如,如果设备为纵向加载pView,则为横向加载lView。下面是我目前尝试的代码Iphone iPad旋转,有没有基于方向加载自定义视图的方法?,iphone,ipad,sdk,orientation,iphone-sdk-3.2,Iphone,Ipad,Sdk,Orientation,Iphone Sdk 3.2,我正在写一个应用程序,我想根据方向显示不同的视图。例如,如果设备为纵向加载pView,则为横向加载lView。下面是我目前尝试的代码 - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation duration:(NSTimeInterval)duration { if (interfaceOrientation == UIInterfaceOrientation
- (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中创建了两个视图,并将插座连接到右侧视图。我也试过:
- (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。有什么想法吗?我必须问一个显而易见的问题:
您的iPad是否已打开屏幕方向锁定开关 根据您要执行的操作,您可以在IB中设置接口以自动处理旋转。你可以调整组件大小,移动图片和标签等等。这可能会做你想做的…我发现以下2个(苹果)示例项目很有用:
另外,请记住,从设备的角度来看,也有朝上和朝下的方向;这让我大吃一惊。不,我试图根据方向加载不同的视图。