iPad旋转,根据方向加载自定义视图的任何方法?
-
30-09-2019 - |
题
我正在编写一个我想根据方向显示不同视图的应用程序。例如,如果设备是肖像负载pview,如果景观负载lview。以下是IVE当前尝试的代码。
- (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。有任何想法吗?
解决方案
我发现以下2(Apple)样本项目有用:
http://developer.apple.com/library/ios/#samplecode/alternateviews/introduction/intro.html
http://developer.apple.com/library/ios/#samplecode/whichwayisup/introduction/introc.html
另外,从设备的角度记住,还有面朝上和面向朝下的方向。这吸引了我。
其他提示
我必须问一个明显的问题:
您是否为iPad打开了屏幕方向锁定开关?
根据您要尝试的操作,您可以在IB中设置接口以自动处理旋转。您可以调整组件的大小,移动图片和标签,以及类似的内容。那可能会做你想做的...
不隶属于 StackOverflow