标签:
override func viewDidLoad() { super.viewDidLoad() let rect=CGRect(x:80,y:200,width:200,height:200); var view1 = UIView(frame: rect) view1.backgroundColor = UIColor.redColor() self.view.addSubview(view1) //1,建立手势识别器 var gesture = UITapGestureRecognizer(target: self, action: "viewAction:") #warning 如果想要识别器能够识别多种触控,例如1点和2点,那就要建立2个UITapGestureRecognizer gesture.numberOfTapsRequired = 2 //点击次数 // gesture.numberOfTouchesRequired = 2 //多点触摸 //2,关联识别器到视图 view1.addGestureRecognizer(gesture) } //3,手势引用的动作 func viewAction(sender:UITapGestureRecognizer){ //获得点击处的位置 var point:CGPoint = sender.locationInView(self.view) println("\(point)") println("clicked") }
override func viewDidLoad() { super.viewDidLoad() //1,建立手势识别器 var gesture = UIPinchGestureRecognizer(target: self, action: "viewAction:") //2,关联识别器到视图 view1.addGestureRecognizer(gesture) } //3,手势引用的动作 func viewAction(sender:UITapGestureRecognizer){ var _height = view1.bounds.height var _width = view1.bounds.width view1.bounds.size = CGSize(width: _width * sender.scale, height: _height * sender.scale) }
标签:
原文地址:http://my.oschina.net/u/2346786/blog/497271