xcode - iOS/Swift: Keep "global" view pan from resetting other objects' positions, w/ AutoLayout ON? -


just started learning swift, following excellent uigesturerecognizer tutorial on ray wenderlich's site. it's got 2 images can move around (pan) , zoom (pinch) , rotate. works fine.

but tried extending adding pan gesture recognizer main view, pan "scene" @ once. hooked viewcontroller in same way 2 images. works, every time pan in main view, resets positions of other objects, i.e. move @ beginning of run, forgetting wherever might have moved them to.

this autolayout issue (as described in thread uilabel causing other objects reset position on ios). (although find weird because there no constraints @ all. whatever.)

turning off autolayout indeed keeps resetting happening, however.... want build app using autolayout other reasons, want autolayout on.

so, added code viewdidload() per uiview frames reset when using autolayout, namely in storyboard, control-dragged "main view" object assistant editor viewcontroller.swift, line says

@iboutlet var mainview: uiview! 

and in viewdidload, added

mainview.translatesautoresizingmaskintoconstraints = true 

but has no effect, i.e. reset behavior still occurs. :-( no warnings "unable simultaneously satisfy constraints" generated.

any help? thanks. running xcode 7 beta 5.

solved! ah. it's other objects, not main view, need code! i.e. code reads...

@iboutlet var mainview: uiview! @iboutlet weak var monkeyview: uiimageview! @iboutlet weak var bananaview: uiimageview!  override func viewdidload() {     super.viewdidload()     // additional setup after loading view, typically nib.      //self.mainview.translatesautoresizingmaskintoconstraints = true // not needed     self.monkeyview.translatesautoresizingmaskintoconstraints = true     self.bananaview.translatesautoresizingmaskintoconstraints = true } 

with these changes, no unwanted resetting occurs, , yet autolayout on! :-)


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -