mafioso mafioso -5 years ago 199
iOS Question

Swift rotate icons when iPad is in landscape mode

Currently my App looks like this in portrait mode:
enter image description here

but when my iPad is in landscape mode I want my Icons look like this:
enter image description here

By now it looks like that in landscape mode:

enter image description here

So my questions is: How can I just rotate the Icons? I don't need something more just the icons should move

Answer Source

Add this line of code to the viewDidLoad method: NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(rotate), name: UIDeviceOrientationDidChangeNotification, object: nil)
and this is the function:

    func rotate(){
 if UIDevice.currentDevice().orientation == UIDeviceOrientation.LandscapeLeft {
     self.takephoto.transform = CGAffineTransformMakeRotation(CGFloat(M_PI_2))
     self.recordButton.transform = CGAffineTransformMakeRotation(CGFloat(M_PI_2))
 } else if UIDevice.currentDevice().orientation == UIDeviceOrientation.LandscapeRight {
     self.takephoto.transform = CGAffineTransformMakeRotation(CGFloat(-M_PI_2))
     self.recordButton.transform = CGAffineTransformMakeRotation(CGFloat(-M_PI_2))
} else if UIDevice.currentDevice().orientation == UIDeviceOrientation.Portrait {
  self.takephoto.transform = CGAffineTransformMakeRotation(CGFloat(0))
  self.recordButton.transform = CGAffineTransformMakeRotation(CGFloat(0))
} else if UIDevice.currentDevice().orientation == UIDeviceOrientation.PortraitUpsideDown {
  self.takephoto.transform = CGAffineTransformMakeRotation(CGFloat(M_PI))
  self.recordButton.transform = CGAffineTransformMakeRotation(CGFloat(M_PI))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download