swift下给控件添加点击事件(双击、捏、旋转、拖动、划动、长按)


//创建,并且初始化尺寸

 let imageview = UIImageView(frame: CGRectMake(20, 5, 90, 90))

        imageview.image = UIImage(named: "icon1")

        imageview.userInteractionEnabled = true            //是否接受用户交互

        let Tap = UITapGestureRecognizer(target: self, action: #selector(SYView.btn))  //创建点击手势,调用方法

        Tap.numberOfTapsRequired = 2   // 设置需要点击的次数

         imageview.addGestureRecognizer(Tap)  //添加点击事件

        view.addSubview(imageview)

    }


UIPinchGestureRecognizer   //捏合的手势

UIRotationGestureRecognizer  //旋转的手势

UIPanGestureRecognizer //  拖得手势

UISwipeGestureRecognizer  //右划手势

UISwipeGestureRecognizer  //左划手势

UILongPressGestureRecognizer // 长按手势  

 //长按时间为1  

.minimumPressDuration=1;  

 //允许15秒中运动  

.allowableMovement=15;  

 //所需触摸1  

.numberOfTouchesRequired=1






你可能感兴趣的:(swift下给控件添加点击事件(双击、捏、旋转、拖动、划动、长按))