码迷,mamicode.com
首页 > 移动开发 > 详细

IOS多点触控与手势识别

时间:2015-08-26 14:07:53      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:

点击-UITapGestureRecognizer

    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")
    }


2, 放大缩放UIPinchGestureRecognizer

    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)
    }



IOS多点触控与手势识别

标签:

原文地址:http://my.oschina.net/u/2346786/blog/497271

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!