如何将UIPanGestureRecognizer添加到在CAShapLayer-swift上绘制的形状上?

时间:2018-09-14 10:15:01

标签: ios swift uipangesturerecognizer

我有一个imageView,它在其图层中绘制了一个蓝色圆圈。我希望用户能够在UIImageView中的任意位置点击,按住并拖动此蓝色圆圈。我不确定如何将此形状附加到UIPanGestureRecognizer上。到目前为止,我的努力如下:

class DrawCircleViewController: UIViewController {

    @IBOutlet weak var imgView: UIImageView!

    override func viewDidLoad() {
        super.viewDidLoad()

        // DRAW A FILLED IN BLUE CIRCLE
        drawBlueCircle()

        // ADD GESTURE RECOGNIZER
        let panRecgonizer = UIPanGestureRecognizer.init(target: ???, action: <#T##Selector?#>)

    }

    func drawBlueCircle(){
        let fourDotLayer = CAShapeLayer()
        fourDotLayer.path = UIBezierPath.init(roundedRect: CGRect.init(x: 60, y: 60, width: 30, height: 30), cornerRadius: 50).cgPath
        fourDotLayer.fillColor = UIColor.blue.cgColor
        self.imgView.layer.addSublayer(fourDotLayer)
    }
}

0 个答案:

没有答案