Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Puzzled with auto layout

dickthedevdickthedev Posts: 214Registered Users @ @
edited May 8 in iOS SDK Development
Hello, I am learning to use auto layout in storyboard. Xcode 8.3.2
I started with iPhone 7, put an square 50x50 UIView at the dead center, it looks just right.
But once I rotated it to landscape, it is completely off. I was expecting to see the square remains in dead center. The same layout, I switched to iPhone 5, even in portrait mode, it is completely off again, and also I was expecting to see the square remains in dead center. What have I done wrong?
And btw, how do I detect the orientation in real time when the user rotates the device?
Thanks.
Post edited by dickthedev on
7.png 12.6K
5.png 10.6K

Replies

  • BrianSlickBrianSlick Treadmill Desk Ninja Posts: 10,690Tutorial Authors, Registered Users @ @ @ @ @ @ @ @
    What constraints have you added?
    dickthedev wrote: »
    And btw, how do I detect the orientation in real time when the user rotates the device?
    Thanks.
    - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
    
    Professional iOS App Development. Available for hire.
    BriTer Ideas LLC - WWW | Facebook | Twitter | LinkedIn

    BTIKit | SlickShopper 2 | Leave a PayPal donation
  • dickthedevdickthedev Posts: 214Registered Users @ @
    Hello, thank you for your reply.
    It looks like you example is in obj-C rather than Swift.
  • BrianSlickBrianSlick Treadmill Desk Ninja Posts: 10,690Tutorial Authors, Registered Users @ @ @ @ @ @ @ @
    It is.
    Professional iOS App Development. Available for hire.
    BriTer Ideas LLC - WWW | Facebook | Twitter | LinkedIn

    BTIKit | SlickShopper 2 | Leave a PayPal donation
  • dickthedevdickthedev Posts: 214Registered Users @ @
    edited May 10
    I found this code in Swift 3 on SO
    import UIKit
    
    class ViewController: UIViewController {
    
        override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
            if UIDevice.current.orientation.isLandscape {
                print("Landscape")
            } else {
                print("Portrait")
            }
        }
    }
    
    
    The code itself seem to work well. But the funky Xcode keeps giving me this warning
    "if we're in the real pre-commit handler we can't actually add any new fences due to CA restriction"
    I have no idea what it mean, what is 'real pre-commit handle' and what are 'new fences' anyway? I tried to silence it and I found a few links suggested put DEBUG_ACTIVITY_MODE with a value disable and also this link http://stackoverflow.com/questions/37800790/hide-strange-unwanted-xcode-8-logs from SO. None of them does the trick. However, the warning doesn't seem to hinders the execution, just an annoyance and misled me too think I did something wrong. It will be nice to perminently get rid of it. :smile:
Sign In or Register to comment.