【问题标题】:Loading different portrait/landscape UIViews加载不同的纵向/横向 UIViews
【发布时间】:2010-06-09 21:30:02
【问题描述】:
我有以下视图控制器结构:
滚动视图控制器
景观视图控制器
PortraitViewController
每个都有自己的 .nib
应用程序以横向模式启动,其中许多横向视图被添加到滚动视图中。每个横向视图都有其特定的纵向视图,因此我必须为每个视图分配类似的 ID。您能告诉我,在旋转设备时如何为每个横向视图加载特定的纵向视图?
我必须制作两个滚动视图吗?一张横向,一张纵向?或者是否可以只滚动横向滚动视图并根据 ID 仅加载一个具有正确内容的纵向视图?我该如何实现呢?
数据来自属性列表。
提前致谢!
【问题讨论】:
标签:
iphone
objective-c
uiview
uiscrollview
rotation
【解决方案1】:
您在 UIViewController 中使用 shouldAutorotateToInterfaceOrientation 来提供您正在寻找的功能。在下面的示例中,我正在切换视图以对应方向变化:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (UIInterfaceOrientationIsPortrait(interfaceOrientation)) {
/* Switch to the portrait view or do any other custom layout changes for current Orientation */
self.view = portraitView;
} else if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
/* Switch to the landscape view or do any other custom layout changes for current Orientation */
self.view = landscapeView;
}
return YES;
}
在您的情况下,您可以使用 shouldAutorotateToInterfaceOrientation 来调整视图大小或切换到相应的纵向视图。
希望对您有所帮助。