应用性能问题

问题描述 投票:2回答:1

我正在做这些功能:

  1. 我正在做Paint Bucket的图像着色。
  2. zoomin用scrollview缩小图像。

合并这两个功能会使我的设备挂起一段时间。

请检查以下代码工作并协助我。

- 在imageView上点击func

  func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool{

        let touchView = gestureRecognizer.view

        if touchView == self.imgViewMy{

            let point : CGPoint = touch.location(in: imgViewMy)
            touchedPoint = point

           self.imgViewMy.image = self.imgDup


            // Doing asysn coloring in image to avoid device hang up.
            DispatchQueue.main.async( execute: {

                print("touch is inside , \(self.touchedPoint!)")

           // Getting scaled coordinates
                let aNewCor = self.getScaledPoint(self.touchedPoint!)

              // Calling Paint Bucket function to change image color. 
                self.imgDup = self.imgDup?.pbk_imageByReplacingColorAt(Int(aNewCor.x),
                                                                       Int(aNewCor.y),
                                                                       withColor: self.colorSel,
                                                                       tolerance: 10)
                self.imgViewMy.image = self.imgDup

           })
       return false
    }
    return false
}

- 用于图像放大和缩小

func viewForZooming(in scrollView: UIScrollView) -> UIView? {
     return imgViewMy
 }
ios swift image performance
1个回答
2
投票

尝试简化并进行一些清理:

func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool{
  let touchView = gestureRecognizer.view
  if touchView == self.imgViewMy {
    let point : CGPoint = touch.location(in: imgViewMy)
    touchedPoint = point
  }
  return true
}

func tapResponse(sender: UITapGestureRecognizer? = nil) {
  let aNewCor = self.getScaledPoint(self.touchedPoint!)
  self.imgViewMy.image = self.imgDup?.pbk_imageByReplacingColorAt(Int(aNewCor.x), Int(aNewCor.y), withColor: self.colorSel, tolerance: 5)
}

在设备上测试,似乎工作正常(它非常敏感)。

© www.soinside.com 2019 - 2024. All rights reserved.