如何仅在图像框中添加人像?

时间:2019-06-08 13:10:10

标签: ios swift uiimageview uiimage

任何人都知道如何迅速在帧中添加人物图像。我在这里尝试过它的视频。现在我确实添加了框架imageview,并且上面我添加了人imageview。但我不知道如何仅在模糊部分中添加人imageview

https://drive.google.com/open?id=18nchB2wh5hqjlcGqxHrsDbtpe9VkEoKd

class ViewController: UIViewController {

@IBOutlet weak var imgFrame : UIImageView!
@IBOutlet weak var imgPerson : UIImageView!
@IBOutlet weak var scrollView : UIScrollView!

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.

    self.imgPerson.isUserInteractionEnabled = true
    let gestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(handlePan))
    self.imgPerson.addGestureRecognizer(gestureRecognizer)

    scrollView.minimumZoomScale = 1.0
    scrollView.maximumZoomScale = 10.0//maximum zoom scale you want
    scrollView.zoomScale = 1.0

    scrollView.delegate = self

}

@IBAction func handlePan(_ gestureRecognizer: UIPanGestureRecognizer) {
    if gestureRecognizer.state == .began || gestureRecognizer.state == .changed {

        let translation = gestureRecognizer.translation(in: self.view)
        // note: 'view' is optional and need to be unwrapped
        gestureRecognizer.view!.center = CGPoint(x: gestureRecognizer.view!.center.x + translation.x, y: gestureRecognizer.view!.center.y + translation.y)
        gestureRecognizer.setTranslation(CGPoint.zero, in: self.view)
    }
}
}

extension ViewController : UIScrollViewDelegate {
func viewForZooming(in scrollView: UIScrollView) -> UIView? {
    return imgPerson
}
}

0 个答案:

没有答案