iOS开发 UI学习笔记 UIGestureRecognizer手势加载

手势一共有七种,分别是轻拍,轻扫,旋转,拖拽,捏合,长按,以及平移。
UIImageView *headImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 02, 100, 100)];
    [headImageView setCenter:self.view.center];
    UIImage *headImage = [UIImage imageNamed:@"Icon.png"];
    headImageView.image = headImage;
    [headImageView setUserInteractionEnabled:YES];

首先初始化一个view来测试手势。


添加轻拍手势:

UITapGestureRecognizer


    /**
     轻拍手势
     
     - parameter hiddenKeyBoard: 回调方法
     */
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hiddenKeyBoard:)];

设置轻拍次数:

tapGesture.numberOfTouchesRequired = 2;

添加轻扫手势

UISwipeGestureRecognizer

UISwipeGestureRecognizer *swipeTouche = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeAction:)];
    //扫动方向
    [swipeTouche setDirection:(UISwipeGestureRecognizerDirectionUp|UISwipeGestureRecognizerDirectionDown)];

添加旋转手势:

UIRotationGestureRecognizer

    //旋转手势
    UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotationAction:)];
    rotation.delegate = self;
    [headImageView addGestureRecognizer:rotation];

添加缩放手势:

UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchAction:)];
    pinch.delegate = self;
    [headImageView addGestureRecognizer:pinch];

添加平移手势:

 UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panAction:)];
    pan.delegate = self;
    [headImageView addGestureRecognizer:pan];

添加长按手势:

UILongPressGestureRecognizer *longPan = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPanAction:)];
    longPan.delegate = self;
    CFTimeInterval minTime = 1.00;
    longPan.minimumPressDuration = minTime;
    [headImageView addGestureRecognizer:longPan];

每个手势添加的时候都有其回调方法;

手势的代理:

<UIGestureRecognizerDelegate>

在代理方法里可以实现多手势的识别

#pragma mark - 代理方法
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
    
    
    
    
    return YES;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值