ios - Pan UImage within superview swift -
i'm attempting move uiimageview
within superview using pan gesture, although i'm able make superview move within self.view not able move 1 of subviews within itself.
these relevant lines in code
let couponoutline = uiview(frame: cgrect(x: 0, y: 0, width: 300, height: 424)) let imageview = uiimageview(image: uiimage(named: "imageplaceholder")) imageview.frame = cgrect(x: 0, y: 0, width: 128, height: 128) imageview.center = cgpoint(x: 230, y: 300) couponoutline.addsubview(imageview) self.view.addsubview(couponoutline) let panrec = uipangesturerecognizer(target: self, action: "moveview:") panrec.minimumnumberoftouches = 1 imageview.addgesturerecognizer(panrec)
in moveview: method
func moveview(sender: uipangesturerecognizer) { println("pan") let couponoutline = view.subviews[0] as! uiview print(couponoutline) var translation = sender.translationinview(self.view) sender.view?.center = cgpoint( x: sender.view!.center.x + translation.x, y: sender.view!.center.y + translation.y) sender.settranslation(cgpoint(x: 0, y: 0), inview: couponoutline)
i'm trying move imageview within couponoutline, when use code not pick of gesture @ (println("pan") no shown).
what use uiscrollview
. follow tutorial linked below(go "scrolling , zooming large image")
Comments
Post a Comment