I am playing around with Pinch Gesture for fun to try to learn, however, I do not see my "PINCH" print statement displayed in the console.
Question
Why does my print("PINCH") statement not show up in the Console when the code is run?
(Note: After the program is running in the simulator, I press the <Option> key and see the two "pinch" circles. I then use the mouse to move the circles closer together and then farther apart)
Initial Setup
- Added a new ViewController in my storyboard
- Created a New Cocoa Touch File (type of ViewController) and called it "GesturesViewController"
- Associated the "GesturesViewController" class with the ViewController object I added previously so they are linked
- Dragged a UIView object on the ViewController and resized it to be large
- Created an IBOutlet of the UIView and called it "letterView" (see code added below)
- Defined the pinch gesture recognizer within the didSet{ } of the IBOutlet letterView to call "processPinch" method (see code below)
- Run the code, do the "pinching" with the two circles and the mouse and the "PINCH" text does not show up in the Console
Code:
import UIKit
class GesturesViewController: UIViewController {
override func viewDidLoad()
{
super.viewDidLoad()
}
@IBOutlet weak var letterView: UIView! {
didSet
{
let pinch = UIPinchGestureRecognizer(target: self, action: #selector(processPinch(_:)))
letterView.addGestureRecognizer(pinch)
}
}
@objc func processPinch(_ sender: UIPinchGestureRecognizer)
{
print("PINCH")
}
}