2016-08-23 20 views
7

Mam działa UIAlertController, ale chcę obrócić alert.view o 90 stopni w lewo.Jak obracać UIAlertController w Swift

Jak mogę to zrobić? Moje kodu jest tutaj poniżej:

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

Próbowałem dodać:

alert.view.transform = CGAffineTransformMakeRotation(CGFloat(M_PI_2)) 

ale to nie działa.

Dziękujemy!

Odpowiedz

8

Z tym kodem:

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

    }) 

Można to osiągnąć:

enter image description here

Updated odpowiedzi

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 
     } 

    }) 
+0

Dziękujemy, zadziałało, ale! Mieć 1 problem, gdy alarm pokazuje najpierw wygląd normalny po 1 sekundzie skrętu o 90 stopni w lewo. Jak możemy to rozwiązać? – SwiftDeveloper

+0

@SwiftDeveloper - ok bro Mam to, daj trochę czasu Mam małą pracę, kończę i zaczynam pracę –

+0

Dziękuję bro, musimy to rozwiązać, myślę, że będzie to pomoc dla wielu ludzi! – SwiftDeveloper

Powiązane problemy