0
0
iOS Swiftmobile~10 mins

Gesture recognition (drag, magnify, rotate) in iOS Swift - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add a pan gesture recognizer to the view.

iOS Swift
let panGesture = UIPanGestureRecognizer(target: self, action: #selector(handlePan))
view.[1](panGesture)
Drag options to blanks, or click blank then click option'
AaddGestureRecognizer
BremoveGestureRecognizer
CbringSubviewToFront
DaddSubview
Attempts:
3 left
💡 Hint
Common Mistakes
Using addSubview instead of addGestureRecognizer
Trying to remove gesture recognizer instead of adding
2fill in blank
medium

Complete the code to get the translation point from the pan gesture recognizer.

iOS Swift
let translation = sender.[1](in: view)
Drag options to blanks, or click blank then click option'
Atranslation
Bstate
Cvelocity
Dlocation
Attempts:
3 left
💡 Hint
Common Mistakes
Using location instead of translation
Using velocity which gives speed, not distance
3fill in blank
hard

Fix the error in the magnification gesture handler to get the scale value.

iOS Swift
func handlePinch(_ sender: UIPinchGestureRecognizer) {
    let scale = sender.[1]
    view.transform = view.transform.scaledBy(x: scale, y: scale)
    sender.scale = 1.0
}
Drag options to blanks, or click blank then click option'
Alocation
Bvelocity
Ctranslation
Dscale
Attempts:
3 left
💡 Hint
Common Mistakes
Using velocity or translation instead of scale
Trying to call a method instead of accessing a property
4fill in blank
hard

Fill both blanks to get the rotation angle and apply it to the view transform.

iOS Swift
func handleRotation(_ sender: UIRotationGestureRecognizer) {
    let rotation = sender.[1]
    view.transform = view.transform.[2](by: rotation)
    sender.rotation = 0
}
Drag options to blanks, or click blank then click option'
Arotation
Bscale
Crotated
DscaledBy
Attempts:
3 left
💡 Hint
Common Mistakes
Using scale property for rotation
Using scaledBy method instead of rotated
5fill in blank
hard

Fill all three blanks to reset the view transform after gestures.

iOS Swift
func resetTransform() {
    UIView.animate(withDuration: [1]) {
        self.view.transform = CGAffineTransform.[2]()
    } completion: { _ in
        print("Transform [3]")
    }
}
Drag options to blanks, or click blank then click option'
A0.3
Bidentity
Creset
D0.5
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong duration value
Using non-existent transform methods
Printing wrong status message