swift -> button operation to get touch position coordinates

 

touchDragInside sliding within the area is equivalent to onTouchMove

 

btn.addTarget(self, action: #selector(xxxxx.touchMoveDrawView), for: .touchDragInside)


    func touchMoveDrawView(sender: AnyObject?,event:UIEvent){
        let button = sender as! UIButton
        let touch:UITouch = (event.touches(for: button)?.first)!
        let location = touch.location(in: button);
        print("x:"+String(describing: location.x)+",y:"+String(describing: location.y));
        
    }

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326266058&siteId=291194637