简体   繁体   中英

Can I change position of draw based on orientation of device

I am trying to create a very basic iOS app using swift 2.0.I have a background image that I would like to draw on top of, but I want the drawing to look consistent in landscape and portrait mode. Using auto layout and constraints would be impossible because the image and its height to width ratio resize whenever the orientation is changed. I'm wondering if I could set some sort of offset from the edge of the page in the vertical and horizontal directions based on the orientation of the device. I have been trying to code it up but have been having trouble. I looked into using UIDeviceOrientation but am not sure how exactly to implement it in code. Any help would be appreciated

I see two ways to do this off the top of my head.. I haven't tried coding it yet however.

  1. set an outlet to the two constraints that's set's the x and y of what you draw on top of the background. Then on the device orientation change you can just change the constraint.constant to a new value that fits better.

  2. You can use the interface builders built in functionality to set constraint based on which sized screen you are dealing with.. You find it at the bottom of the interface builder main view... default values are "w: Any, h: Any"

Animal's second idea is great. You can try it here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM