1
votes

I can detect the button pressed in UIView through this simple code

func handlePan(recognizer:UIPanGestureRecognizer) {
    if let buttonRecognize = recognizer.view as? UIButton {
             let subviews = self.view.subviews as [UIView]
                    for v in subviews {
                        if let button = v as? UIButton {
                            if button.tag != -1  {
                               var p = button.superview?.convertPoint(button.center, toView: view)
                               println(p)
                }

    UIView.animateWithDuration(Double(slideFactor * 2),
            delay: 0,

            options: UIViewAnimationOptions.CurveEaseOut,
            animations: {recognizer.view!.center = finalPoint },
            completion: nil)
        }}}}
}

As can detect the position of a button in UIView ?

for (0,0) of Uiview = (367.666656494141,207.33332824707) for func handlePan

I would like to find the value of the button than the UIView where the center is that of UIView itself and not the value of func handlePan where the center is the top left corner !!

P.S. I tried to move the let subview etc after

completion: nil

but the result does not change !!

1
Can you be more specific, where and when would you want to detect that button? - Marius Fanu

1 Answers

1
votes

You can convert a point coordinate system to that of the specified view using

convertPoint(_ point: CGPoint, toView view: UIView?)

The toView is the coordinate system to which it will be converted.