我正在执行这些功能:
我正在通过 Paint Bucket 对图像进行着色。
使用 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/