ios - Detect collision of two UIView's in swift -
i have 2 uiviews on viewcontroller. added pangesture first view , when start moving view second view move towards first view. want detect event when these 2 views collides. here code.
@ibaction func dragfirstview(sender: uipangesturerecognizer) { let translation = sender.translationinview(self.view) dispatch_async(dispatch_get_main_queue()) { () -> void in uiview.animatewithduration(2.5, delay: 0.0, options: uiviewanimationoptions.curveeaseout, animations: { self.secondview.frame = cgrectmake(sender.view!.center.x + translation.x, sender.view!.center.y + translation.y, self.secondview.frame.size.width, self.secondview.frame.size.height) }, completion: nil) } sender.view!.center = cgpoint(x: sender.view!.center.x + translation.x, y: sender.view!.center.y + translation.y) sender.settranslation(cgpointzero, inview: self.view) }
what
if (cgrectintersectsrect(secondview.frame, sender.frame)) { // }
cgrectintersectsrect(::) : returns whether 2 rectangles intersect.
Comments
Post a Comment