gpt4 book ai didi

ios - 如何在 Swift 中旋转 UIAlertController

转载 作者:搜寻专家 更新时间:2023-10-30 21:52:42 25 4
gpt4 key购买 nike

我有一个可用的 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))

但它不起作用。

谢谢!

最佳答案

使用这段代码:

let alert = UIAlertController(title: "", message: "Message Sample", preferredStyle: .Alert)
alert.addAction(UIAlertAction(title: "Okay", style: .Default){(action)->() in })

self.presentViewController(alert, animated: true, completion: {() -> Void in
alert.view.transform = CGAffineTransformMakeRotation(CGFloat(M_PI_2))

})

Swift3

let alert = UIAlertController(title: "", message: "Message Sample", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Okay", style: .default){(action)->() in })

self.present(alert, animated: true, completion: {() -> Void in
alert.view.transform = CGAffineTransform(rotationAngle: CGFloat(Double.pi/2) )

})

你可以做到这一点:

enter image description here

更新的答案

 self.presentViewController(alert, animated: true, completion: {() -> Void in
// alert.view.transform = CGAffineTransformMakeRotation(CGFloat(M_PI_2))

UIView.animateWithDuration(1.0, delay: 0, options: .CurveLinear, animations: { () -> Void in
alert.view.transform = CGAffineTransformMakeRotation(CGFloat(M_PI_2))
}) { (finished) -> Void in
// do something if you need
}

})

关于ios - 如何在 Swift 中旋转 UIAlertController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39098700/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com