Swift 4:在UIimage视图(PanGestureRecognizer)中添加子视图

时间:2018-09-26 12:13:52

标签: ios swift uiimageview uipangesturerecognizer

如何在移动中(PanGestureRecognizer)在UIImageView中添加子视图?

我的代码:

@IBOutlet weak var img: UIImageView!

@objc func PanAction(sender: UIPanGestureRecognizer) {
    let imageViewPoint:CGPoint = sender.location(in: img)

    var imx:UIImageView?
    imx =  UIImageView.init(image: #imageLiteral(resourceName: "small"))
    img.addSubview(imx!)
    imx!.frame.origin = imageViewPoint
}

代码效果不佳,请参见图片。

-正确显示我的代码(✗)

-我需要像左图(✓)一样的结果

enter image description here

0 个答案:

没有答案