반응형
iOS 15.5, Xcode 13.31, Swift 5, UIKit 환경에서 진행했습니다.
import UIKit
class UIPinchViewController: UIViewController {
lazy var label: UILabel = {
var label = UILabel()
label.backgroundColor = .red
label.text = "Pinch Test"
label.frame = CGRect(x: 50, y: 50, width: 200, height: 50)
return label
}()
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .blue
view.addSubview(label)
let pinchGesture = UIPinchGestureRecognizer(target: self, action: #selector(handlePinch(_:)))
view.addGestureRecognizer(pinchGesture)
}
@objc func handlePinch(_ gesture: UIPinchGestureRecognizer) {
if gesture.state == UIGestureRecognizer.State.changed {
let transform = CGAffineTransform(scaleX: gesture.scale, y: gesture.scale)
view.transform = transform
}
}
}
핀치 기능을 활용하려는 뷰에 addGestureRecognizer 메소드를 통해 제스쳐를 등록하여 핀치 기능을 활용할 수 있다.
[Xcode, Simulator] Xcode simulator pinch 기능
반응형
'iOS > 코드조각' 카테고리의 다른 글
[iOS, Swift] UIRotationGestureRecognizer 예제 (0) | 2022.08.25 |
---|---|
[Xcode, Simulator] Xcode simulator gesture 기능(pinch, rotate) (0) | 2022.08.25 |
[iOS, Swift] UISwipeGestureRecognizer 예제 (0) | 2022.08.25 |
[iOS, Swift] UITextField 특정 글자 제한하기 (0) | 2022.08.21 |
[iOS, Swift] UIAlertController 텍스트 입력창 추가하기 (0) | 2022.08.21 |