Solution for Ch 19 Silver Challenge: Mysterious Lines

Move line (PanGesture) only when (long) pressing on a line. So the UIPanGestureRecognizer need to know the state of UILongPressGestureRecognizer.

Define longPressRecognizer as a property in class DrawView

var longPressRecognizer: UILongPressGestureRecognizer!

Update initializer init?(coder:) accordingly

// let longPressRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(DrawView.longPress(_:)))
longPressRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(DrawView.longPress(_:)))

Update moveLine(_ gestureRecognizer: UIPanGestureRecognizer)

print("Recognized a pan")  
guard longPressRecognizer.state == .changed || longPressRecognizer.state == .ended else {
    return
}
1 Like

Hi hkray!

what is your reasoning to also check if

longPressRecognizer.state == .ended

in your guard statement? I only check for .changed and it seems to work fine.

best regard
B

@BrutusD, You are correct. Since no specific action for the .ended state, it could be removed in the condition checking.