2

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

mafioso
  • 1,630
  • 4
  • 25
  • 45

3 Answers3

2

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))
 }
}
mafioso
  • 1,630
  • 4
  • 25
  • 45
0

Start with supporting just portrait mode. You can observe for UIDeviceOrientationDidChangeNotification in your controller like: https://stackoverflow.com/a/12086463/4209778

Then based on your orientation you can rotate your icons using CGAffineTransformMakeRotation by (+/-)90 degree.

Community
  • 1
  • 1
SHN
  • 785
  • 7
  • 23
0

In your view controller override viewWillTransitionToSize:withTransitionCoordinator: and rote your images using: imageView.transform = CGAffineTransformMakeRotation(CGFloat(M_PI_2))

EG:

override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
    super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)

    let isPortrait = size.height > size.width
    imageView.transform = CGAffineTransformMakeRotation(CGFloat(isPortrait ? 0 : M_PI_2))
}
Daniel Sumara
  • 2,234
  • 20
  • 25