ios - Setting boundary for PanGesture for imageView -


i working on emoji photo app users can add emoji on photos phone , share on instagram , more.

users can zoom, rotate, , drag emojis anywhere want decorate photos , want set boundary emoji can't dragged outside photo. setting boundary seems work except when user drags emoji fast (swiping fast) - emoji can dragged outside photo , disappear completely. attaching code handlepan , screenshot of app.

can see why/how emoji can move outside boundary when user drags fast? appreciated. thanks!

@ibaction func handlepan(recognizer:uipangesturerecognizer) {     if(deletemode) {         return     }      let translation = recognizer.translationinview(self.view)     var centerx: cgfloat!     var centery: cgfloat!     var ipadleftboundary: cgfloat!      if let view = recognizer.view {          if(is_ipad) {             ipadleftboundary = 55         } else {             ipadleftboundary = 0         }          print("panelbackground.frame.origin.x: \(panelbackground.frame.origin.x)")         print("view.center.x: \(view.center.x)")         print("panelbackground.frame.origin.y: \(panelbackground.frame.origin.y)")         print("view.center.y: \(view.center.y)")         print("panelbackground width: \(panelbackground.frame.size.width)")          // setting boundary x         if(view.center.x + translation.x < panelbackground.frame.origin.x - ipadleftboundary) {             centerx = view.center.x + translation.x + 20         } else if(view.center.x > panelbackground.frame.size.width){             centerx = view.center.x + translation.x - 20         } else {             centerx = view.center.x + translation.x         }         // setting boundary y         if(view.center.y + 20 < panelbackground.frame.origin.y - 60){             centery = view.center.y + translation.y + 20         } else if(view.center.y > panelbackground.frame.size.height){             centery = view.center.y + translation.y - 20         } else {             centery = view.center.y + translation.y         }          // set final position         view.center = cgpoint(x:centerx, y:centery)         recognizer.settranslation(cgpointzero, inview: self.view)      } } 

screenshot of app


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -