横向和纵向的不同视图 - Xcode 6
Different views for landscape and portrait - Xcode 6
我正在制作一个项目,其中我需要一个水平方向的视图和另一个垂直方向的视图。我还需要在水平视图中有一个集合视图,在我的垂直视图中有一个 table 视图。
我一直在努力寻找一些教程,但没有成功,或者解决方案太旧了。我正在使用 Xcode 6.
但是您可以使用集合视图实现与 table 视图等效的功能。集合视图基本上是 table 类固醇视图:更强大、更可配置、更通用。与其尝试实现两种类型的视图并在它们之间切换,适合 Apple 模式的设计将只包含一个集合视图,它在横向模式下以两列或三列显示项目,但在纵向模式下仅显示一列.
This article 描述了如何为集合视图实现自定义布局,它包含指向其他相关 material.
的链接
如果您需要做的只是从集合视图切换到 table 视图,那么按照@BrettDonald 所说的进行操作。但是,如果您需要一种更通用的方式来切换视图,请在您的视图控制器中实现它:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[self.dynamicView removeFromSuperView];
if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {
self.dynamicView = [[LandscapeView alloc] initWithFrame:self.view.bounds];
} else {
self.dynamicView = [[PortraitView alloc] initWithFrame:self.view.bounds];
}
[self.view addSubview:self.dynamicView];
}
willRotateToInterfaceOrientation
实际上在 iOS 8 中已弃用,因此您还需要 运行 建议的 viewWillTransitionToSize:withTransitionCoordinator:
中的相同代码。
我正在制作一个项目,其中我需要一个水平方向的视图和另一个垂直方向的视图。我还需要在水平视图中有一个集合视图,在我的垂直视图中有一个 table 视图。
我一直在努力寻找一些教程,但没有成功,或者解决方案太旧了。我正在使用 Xcode 6.
但是您可以使用集合视图实现与 table 视图等效的功能。集合视图基本上是 table 类固醇视图:更强大、更可配置、更通用。与其尝试实现两种类型的视图并在它们之间切换,适合 Apple 模式的设计将只包含一个集合视图,它在横向模式下以两列或三列显示项目,但在纵向模式下仅显示一列.
This article 描述了如何为集合视图实现自定义布局,它包含指向其他相关 material.
的链接如果您需要做的只是从集合视图切换到 table 视图,那么按照@BrettDonald 所说的进行操作。但是,如果您需要一种更通用的方式来切换视图,请在您的视图控制器中实现它:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[self.dynamicView removeFromSuperView];
if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {
self.dynamicView = [[LandscapeView alloc] initWithFrame:self.view.bounds];
} else {
self.dynamicView = [[PortraitView alloc] initWithFrame:self.view.bounds];
}
[self.view addSubview:self.dynamicView];
}
willRotateToInterfaceOrientation
实际上在 iOS 8 中已弃用,因此您还需要 运行 建议的 viewWillTransitionToSize:withTransitionCoordinator:
中的相同代码。