【问题标题】:How to hide a TextView in iOS-landscape如何在 iOS 横向中隐藏 TextView
【发布时间】:2014-07-30 22:01:48
【问题描述】:
我是 iOS 编程的新手(尝试将我的 android 应用程序转换为 iOS)。
我正在使用情节提要并想创建一个视图,该视图顶部有一个滚动视图(内部有一个 ImageView),底部有一个 TextView。如果用户使用纵向,这应该是视图。
现在我希望横向的 ViewCONtroller 只显示滚动视图和图像视图(位于滚动视图内)。文本视图应该隐藏在横向中。
是否可以使图像更大,但保持纵横比(在 android:adjustViewBounds 中)?
我该如何处理?我尝试过使用“自动调整大小”,但结果并不好。
【问题讨论】:
标签:
ios
landscape
aspect-ratio
portrait
【解决方案1】:
Apple 提供了一个方法,当应用改变其方向时调用该方法。
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
[textview setHidden:YES];
} else {
[textview setHidden:NO];
}
}
只需将它添加到您的视图控制器。查看更多Apple's reference