var rotation: CGFloat = 0
var scale: CGFloat = 1
override func viewDidLoad() {
super.viewDidLoad()
//1. 視圖默認(rèn)可以接收觸摸事件
let firstView = FirstView(frame: CGRect(x: 100, y: 100, width: 300, height: 300))
//當(dāng)父視圖不能交互時,所有子視圖都不能交互
//UIImageView: 默認(rèn)為false,不能交互
// firstView.userInteractionEnabled = false
firstView.backgroundColor = UIColor.redColor()
self.view.addSubview(firstView)
//2. 視圖結(jié)構(gòu)不能改變事件傳遞順序
let secondView = SecondView(frame: CGRect(x: 0, y: 0, width: 150, height: 150))
//用戶是否可以交互
//UIView默認(rèn)為true
// secondView.userInteractionEnabled = false
secondView.backgroundColor = UIColor.greenColor()
// self.view.addSubview(secondView)
firstView.addSubview(secondView)
let rotate = UIRotationGestureRecognizer(target: self, action: #selector(didRotate(_:)))
firstView.addGestureRecognizer(rotate)
let pinch = UIPinchGestureRecognizer(target: self, action: #selector(didPinch(_:)))
firstView.addGestureRecognizer(pinch)
}
//旋轉(zhuǎn)
func didRotate(sender: UIRotationGestureRecognizer) {
let firstView = sender.view!
// firstView?.transform = CGAffineTransformMakeRotation(sender.rotation)
firstView.transform = CGAffineTransformRotate(firstView.transform, sender.rotation - rotation)
rotation = sender.rotation
print(sender.rotation)
if sender.state == .Ended {
rotation = 0
}
//手勢每次都是從0開始
print("rotate: ", sender.rotation)
}
//放大、縮小
func didPinch(sender: UIPinchGestureRecognizer) {
let firstView = sender.view!
//??????
firstView.transform = CGAffineTransformScale(firstView.transform, sender.scale - scale + 1 , sender.scale - scale + 1)
scale = sender.scale
if sender.state == .Ended {
scale = 1
}
print("scale: ", sender.scale)
}
View的旋轉(zhuǎn)和放大縮小
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
相關(guān)閱讀更多精彩內(nèi)容
- 【蝴蝶效應(yīng)】 蝴蝶效應(yīng):上個世紀(jì)70年代,美國一個名叫洛倫茲的氣象學(xué)家在解釋空氣系統(tǒng)理論時說,亞馬遜雨林一只蝴蝶...
- Adapter(適配器模式) 適配器模式用于填補(bǔ)現(xiàn)有程序和所需程序之間的差異 Adapter模式有以下兩種 類適配...