UI中提供的七种手势

<span style="font-size:18px;">  
    //UIImage对象的初始化
    /*
    //第一种
//    _imV = [[UIImageView alloc]initWithFrame:CGRectMake(50 , 50, 200, 300)];
//    self.imV.image =[UIImage imageNamed:@"1.png"];
//    _imV.backgroundColor = [UIColor redColor];

    //第二种
//    _imV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"1.png"]];
//    _imV.frame = CGRectMake(50, 50, 200, 300);
*/
    //第三种
    
     //highlighted是UIImageView的一个属性.其默认值是NO.当其值是YES的时候显示高亮状态下的图片
    _imV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"美女.jpg"] highlightedImage:[UIImage imageNamed:@"1.jpg"]];
    _imV.frame = CGRectMake(10, 10, 300, 500);
   
    //Image比较特殊,交互默认是关闭的,(userInteractionEnabled)是要手动打开的.
    _imV.userInteractionEnabled = YES;
//    self.imV.highlighted = YES;
    [self addSubview:_imV];
    /*
     //UIImage的初始化的两种方法
     //方法一
     UIImage *image = [UIImage imageNamed:@"1.png"];
     //方法二
     NSString *str = [[NSBundle mainBundle]pathForResource:@"1" ofType:@"png"];
     UIImage *image1 = [UIImage imageWithContentsOfFile:str];
     */
    
    //七大手势
    //建议一个视图上只加一种手势
    /*
    //第一种手势(轻拍)
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction)];
    //点击多少次响应事件
//    tap.numberOfTapsRequired = 1;
    //用几个手指点击
//    tap.numberOfTouchesRequired = 2;
    [_imV addGestureRecognizer:tap];
    
    //第二种手势(长按)
    UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPressAction)];
    [self.imV addGestureRecognizer:longPress];
    
    //第三种手势(旋转)
    UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotationAction:)];
    [_imV addGestureRecognizer:rotation];
   */
    //第四种手势(捏合)
    UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchAction:)];
    [_imV addGestureRecognizer:pinch];
    
    
    //第五种手势(平移)
    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panAction:)];
    
    [_imV addGestureRecognizer:pan ];
    /*
    //第六种手势(轻扫)
    UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipe)];
    [_imV addGestureRecognizer:swipe];
    
    //第七种手势(屏幕边缘识别器)
    UIScreenEdgePanGestureRecognizer *screen = [[UIScreenEdgePanGestureRecognizer alloc]initWithTarget:self action:@selector(screen)];
    screen.edges = UIRectEdgeRi ght;
    [self addGestureRecognizer:screen];
     
    */
}

-(void)pinchAction:(UIPinchGestureRecognizer*)sender{
    NSLog(@"捏合");
    self.imV.transform = CGAffineTransformScale(self.imV.transform, sender.scale, sender.scale);
    sender.scale = 0;
}

-(void)rotationAction:(UIRotationGestureRecognizer*)sender{
    NSLog(@"旋转");
    self.imV.transform = CGAffineTransformRotate(self.imV.transform, sender.rotation);
    sender.rotation = 0;
}

-(void)panAction:(UIPanGestureRecognizer *)sender{
    
    CGPoint point = [sender translationInView:self.imV];
//    self.imV.transform =CGAffineTransformMakeTranslation(point.x, point.y);
    self.imV.transform = CGAffineTransformTranslate(self.imV.transform, point.x, point.y);
    [sender setTranslation:CGPointZero inView:self.imV];
}




/*
-(void)screen{
    NSLog(@"边缘识别器");
}

-(void)swipe{
    NSLog(@"轻扫");
}

-(void)panAction{
    NSLog(@"平移");
}
-(void)pinchAction{
    NSLog(@"捏合");
}

-(void)rotationAction{
    NSLog(@"旋转");
}

-(void)longPressAction{
    NSLog(@"长按");
}

-(void)tapAction{

    self.imV.highlighted = !self.imV.highlighted;
//    if (_imV.highlighted == YES) {
//        _imV.highlighted = NO;
//    }else{
//        _imV.highlighted = YES;
//    }
}
*/
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
</span>


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值