userInteractionEnabled交互性

<span style="font-weight: normal;">- (void)viewDidLoad
{
    [super viewDidLoad];
    
    imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Fav_Filter_ALL_HL"]];
    imageView.frame = CGRectMake(100, 100, 100, 100);
    [self.view addSubview:imageView];
    
    /*
     当前视图设为view=bigimgView.userInteractionEnabled=NO 时,当前视图不可交互,该视图上面的子视图也不可交互(不可响应),响应事件传递到下面的父视图。
     当前视图设为view=bigimgView.userInteractionEnabled=YES 时,当前视图可交互,该视图上面的子视图可以交互(可以响应),下面的父视图不会接收到响应。
     
     uiimageview 默认的userInteractionEnabled是NO;
     UIView的userInteractionEnabled默认是YES。
     
     
     对比enabled
     uibutton.enabled=YES;//可点
     uibutton.enabled=NO;//不可点
     */
    self.view.userInteractionEnabled = YES;
}</span>

//手指开始触摸会调用
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesBegan:touches withEvent:event];
    
    UITouch *touch = [touches anyObject];
    //获取当前手指点击的中心坐标
    CGPoint point = [touch locationInView:self.view];
    
    //改变图片的中心坐标
    imageView.center = point;
    
    //NSLog(@"%@",NSStringFromCGPoint(point));
    
}

//手指在屏幕上移动会调用
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesMoved:touches withEvent:event];
    
    UITouch *touch = [touches anyObject];
    //获取当前手指点击的中心坐标
    CGPoint point = [touch locationInView:self.view];
    
    //改变图片的中心坐标
    imageView.center = point;
    
    //NSLog(@"touchesMoved");
}

//手指离开屏幕会调用
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesEnded:touches withEvent:event];
    
    NSLog(@"touchesEnded");
}



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值