保留 iPhone X home 指示器的纵向位置
Retain the portrait position of the iPhone X home indicator
有没有办法在屏幕方向为横向的情况下以纵向显示主页指示器?
您不能修改主页指示器的位置。这也是糟糕的用户体验,因为用户希望它位于底部。
解决此问题的方法是使用 CGAffineTransform
旋转所有 UI 元素的超级视图。为此,you should only allow the portrait orientation in your app (or ),以便用户界面始终以横向显示。
view.transform = CGAffineTransform(rotationAngle: .pi / 2)
...或左侧横向:
view.transform = CGAffineTransform(rotationAngle: .pi / -2)
此外,请记住,您的旋转超级视图应该翻转其视图和高度,以便它填满整个屏幕。例如,您应该将其大小从 320x568 调整为 568x320。
正如@the4kman 指出的那样,实现这一目标的唯一方法是使用视图转换:
view.transform = CGAffineTransform(rotationAngle: .pi / 2)
而且,要转化的观点应该是内心的观点。你需要设置它的 height 等于 superview width 并且它的 width 等于 superview height。并且它应该垂直和水平居中。
You can support all orientations in your app and only disable it for
that specific controller.
视图控制器实现:
import UIKit
class PortraitController: UIViewController {
@IBOutlet weak var viewLandscaped: UIView!
override func viewDidLoad() {
super.viewDidLoad()
viewLandscaped.transform = CGAffineTransform(rotationAngle: .pi / 2)
}
override var supportedInterfaceOrientations : UIInterfaceOrientationMask {
return .portrait
}
}
结果:
有没有办法在屏幕方向为横向的情况下以纵向显示主页指示器?
您不能修改主页指示器的位置。这也是糟糕的用户体验,因为用户希望它位于底部。
解决此问题的方法是使用 CGAffineTransform
旋转所有 UI 元素的超级视图。为此,you should only allow the portrait orientation in your app (or
view.transform = CGAffineTransform(rotationAngle: .pi / 2)
...或左侧横向:
view.transform = CGAffineTransform(rotationAngle: .pi / -2)
此外,请记住,您的旋转超级视图应该翻转其视图和高度,以便它填满整个屏幕。例如,您应该将其大小从 320x568 调整为 568x320。
正如@the4kman 指出的那样,实现这一目标的唯一方法是使用视图转换:
view.transform = CGAffineTransform(rotationAngle: .pi / 2)
而且,要转化的观点应该是内心的观点。你需要设置它的 height 等于 superview width 并且它的 width 等于 superview height。并且它应该垂直和水平居中。
You can support all orientations in your app and only disable it for that specific controller.
视图控制器实现:
import UIKit
class PortraitController: UIViewController {
@IBOutlet weak var viewLandscaped: UIView!
override func viewDidLoad() {
super.viewDidLoad()
viewLandscaped.transform = CGAffineTransform(rotationAngle: .pi / 2)
}
override var supportedInterfaceOrientations : UIInterfaceOrientationMask {
return .portrait
}
}