ios六大手势的创建使用

来源:互联网 发布:java流程管理系统 编辑:程序博客网 时间:2024/06/06 18:55

点击手势

    //创建点击手势    UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(TapMe)];    //控制点击此时    tap.numberOfTapsRequired=3;    //创建图片控件    UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 100, 100)];    //设置图片是可交互的    imageView.userInteractionEnabled=YES;    [self.view addSubview:imageView];    //为图片控件添加手势    [imageView addGestureRecognizer:tap];

长按手势

    //创建长按手势    UILongPressGestureRecognizer *longP=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPressMe)];    //控制长按事件(按多少秒触发)    longP.minimumPressDuration=3;    //控制长按过程中手指允许移动的范围    longP.allowableMovement=50;    [imageView addGestureRecognizer:longP];

轻扫手势

    //创建轻扫手势    UISwipeGestureRecognizer *swip=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipMe)];    [imageView addGestureRecognizer:swip];

缩放手势

    //缩放手势    UIPinchGestureRecognizer *pinch=[[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchMe)];    [imageView addGestureRecognizer:pinch];

拖拽手势

    //拖拽手势    UIPanGestureRecognizer *pan=[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panMe)];    [imageView addGestureRecognizer:pan];

旋转手势

    //旋转手势    UIRotationGestureRecognizer *rotation=[[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotationMe)];    [imageView addGestureRecognizer:rotation];
原创粉丝点击