ios - 应用程序性能问题

标签 ios swift image performance

我正在执行这些功能:

  1. 我正在通过 Paint Bucket 对图像进行着色。

  2. 使用 ScrollView 放大缩小图像。

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

请检查下面的代码工作并帮助我。

- 点击 imageView 上的功能

  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
 }

最佳答案

尝试使其变得简单并进行一些清理:

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)
}

在设备上进行了测试,似乎工作正常( react 非常灵敏)。

关于ios - 应用程序性能问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47900314/

相关文章:

python-3.x - OpenCV 图像去噪给出 : Error: -215:Assertation failed

javascript - 如何设置 <alt> 标签字符串的样式?

iphone - 你如何设计 iOS 组件的样式?

ios - 如何从 Objective-C 中的文本文件解析坐标?

ios - 如何从另一个图像的一部分创建图像?

ios - 在 Swift 3.0 中从异步线程调用 UIAlertController

swift - 使用 Swift AirPrint TextView 的内容

ios - Xcode 快速删除按钮

ios - 如果电子邮件未经验证,如何不让用户注册

java - 如何在我的 UI 中使用 vaadin 显示图片