IOS中的六大手势

来源:互联网 发布:剑三眼睛捏脸数据 编辑:程序博客网 时间:2024/06/05 07:42
/*六大手势:1.轻拍,单击,双击,多指点击 2.长按 3.轻扫,分上下左右四个方向 4.旋转
     5.捏合,放大缩小  6.拖拽,移动位置   */
    UIView *aView = [[UIView alloc] initWithFrame:CGRectMake(30, 30, 280, 280)];
    aView.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:aView];
    [aView release];
    //轻拍手势
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(changeViewBackgroundColor:)];
    tapGesture.numberOfTapsRequired = 2;
    tapGesture.numberOfTouchesRequired = 2;
    [aView addGestureRecognizer:tapGesture];
    [tapGesture release];
    //长按手势
    UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(changeViewBackgroundColor:)];
    longPress.minimumPressDuration = 2.0;
    [aView addGestureRecognizer:longPress];
    [longPress release];
    //轻扫手势
    UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(changeViewBackgroundColor:)];
    [aView addGestureRecognizer:swipeGesture];
    swipeGesture.direction = UISwipeGestureRecognizerDirectionDown;
    [swipeGesture release];
    //拖动手势
    UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAction:)];
    [aView addGestureRecognizer:panGesture];
    [panGesture release];
    //捏合手势
    UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchAction:)];
    [aView addGestureRecognizer:pinchGesture];
    [pinchGesture release];
    //旋转手势
    UIRotationGestureRecognizer *rotationGesture = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationAction:)];
    [aView addGestureRecognizer:rotationGesture];
    [rotationGesture release];
0 0
原创粉丝点击