Image editor fixes.

This commit is contained in:
Matthew Chen 2018-12-19 14:41:26 -05:00
parent 17c3ba0580
commit 5dcde44486
3 changed files with 8 additions and 6 deletions

View file

@ -10,7 +10,7 @@ class ImageEditorGestureRecognizer: UIGestureRecognizer {
public var shouldAllowOutsideView = true
@objc
public weak var referenceView: UIView?
public weak var canvasView: UIView?
@objc
override func canPrevent(_ preventedGestureRecognizer: UIGestureRecognizer) -> Bool {
@ -105,8 +105,8 @@ class ImageEditorGestureRecognizer: UIGestureRecognizer {
owsFailDebug("Missing gestureView")
return .invalid
}
guard let referenceView = referenceView else {
owsFailDebug("Missing referenceView")
guard let canvasView = canvasView else {
owsFailDebug("Missing canvasView")
return .invalid
}
guard let allTouches = event.allTouches else {
@ -132,8 +132,8 @@ class ImageEditorGestureRecognizer: UIGestureRecognizer {
}
// Reject new touches outside this GR's view's bounds.
let location = firstTouch.location(in: referenceView)
if !referenceView.bounds.contains(location) {
let location = firstTouch.location(in: canvasView)
if !canvasView.bounds.contains(location) {
if shouldAllowOutsideView {
// Do nothing
} else if isNewTouch {

View file

@ -500,6 +500,8 @@ public class ImageEditorModel: NSObject {
public func crop(unitCropRect: CGRect) {
guard let croppedImage = ImageEditorModel.crop(imagePath: contents.imagePath,
unitCropRect: unitCropRect) else {
// Not an error; user might have tapped or
// otherwise drawn an invalid crop region.
Logger.warn("Could not crop image.")
return
}

View file

@ -69,7 +69,7 @@ public class ImageEditorView: UIView, ImageEditorModelDelegate {
self.isUserInteractionEnabled = true
layersView.isUserInteractionEnabled = true
let editorGestureRecognizer = ImageEditorGestureRecognizer(target: self, action: #selector(handleTouchGesture(_:)))
editorGestureRecognizer.referenceView = layersView
editorGestureRecognizer.canvasView = layersView
self.addGestureRecognizer(editorGestureRecognizer)
self.editorGestureRecognizer = editorGestureRecognizer