如何在Swift中旋转UIAlertController

Swi*_*per 7 uialertview ios swift uialertcontroller swift3

我有一个工作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) {}
Run Code Online (Sandbox Code Playgroud)

我试着添加:

 alert.view.transform = CGAffineTransformMakeRotation(CGFloat(M_PI_2))
Run Code Online (Sandbox Code Playgroud)

但它不起作用.

谢谢 !

Anb*_*hik 9

使用此代码:

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))

})
Run Code Online (Sandbox Code Playgroud)

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) )

    })
Run Code Online (Sandbox Code Playgroud)

你可以实现这个目标:

在此输入图像描述

更新的答案

 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
        }

    })
Run Code Online (Sandbox Code Playgroud)