我有一个可以工作的UIAlertController
,但我想将alert.view
向左旋转90度。
我该怎么做呢?我的代码如下:
let alert = UIAlertController(title: "", message: "Message Sample", preferredStyle: .Alert)
alert.addAction(UIAlertAction(title: "Okay", style: .Default){(action)->() in })
presentViewController(alert, animated: true) {}
我试着补充说:
alert.view.transform = CGAffineTransformMakeRotation(CGFloat(M_PI_2))
但它不起作用。
谢谢!
发布于 2018-06-01 07:02:00
我认为这可能会在FaceID中更频繁地出现。我必须解决这个问题,因为我有一个处于横向模式的应用程序,但当用户在iPhone上启动应用程序时,或者当他们必须使用FaceID对应用程序进行身份验证时,他们通常处于纵向模式。所以我想根据用户拿着手机的方式来显示提醒。我的解决方案是扩展UIAlertController类,如下所示;
extension UIAlertController {
open override func viewWillAppear(_ animated: Bool) {
view.isHidden = true
}
override open func viewDidAppear(_ animated: Bool) {
let appDirection = UIApplication.shared.statusBarOrientation
let deviceDirection = UIDevice.current.orientation
var direction:CGFloat = 0
if deviceDirection == .portrait {
if appDirection == .landscapeLeft {
direction = 1.0
} else if appDirection == .landscapeRight {
direction = -1.0
}
} else if deviceDirection == .portraitUpsideDown {
if deviceDirection == .landscapeLeft {
direction = -1.0
} else if appDirection == .landscapeRight {
direction = 1.0
}
}
if direction != 0 {
view.transform = CGAffineTransform(rotationAngle: CGFloat(Double.pi / 2) * direction);
}
view.isHidden = false
}
open override func viewWillDisappear(_ animated: Bool) {
view.isHidden = true
}
}
发布于 2019-01-24 19:55:17
如果您的应用程序支持landscapeRight、landscapeLeft和default (如纵向),您可以尝试这样做
self.present(alertController, animated: false, completion: {
switch UIDevice.current.orientation {
case .landscapeRight:
self.alertController.view.transform=CGAffineTransform(rotationAngle: CGFloat(-Double.pi / 2))
case .landscapeLeft:
self.alertController.view.transform=CGAffineTransform(rotationAngle: CGFloat(Double.pi / 2))
default:
self.alertController.view.transform=CGAffineTransform.identity
}
})
这将根据您的屏幕旋转旋转您的警报视图,而不会产生任何UI动画问题。
https://stackoverflow.com/questions/39098700
复制相似问题