【问题标题】:[IOS SDK]- touchesBegan with specific object?[IOS SDK]-touchesBegin 与特定对象?
【发布时间】:2010-12-17 17:53:44
【问题描述】:

当我触摸屏幕上的任何位置时触发 touchesBegan 事件。但是如果我触摸 UIImageView 之类的特定对象,我无法管理?

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

 UITouch *touch = [[event allTouches] anyObject];

 CGPoint location = [touch locationInView: touch.view];

 imageView.center = location;

}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

 [self touchesBegan:touches withEvent:event];

}

【问题讨论】:

    标签: xcode ios4 touchesbegan nsset touchesmoved


    【解决方案1】:

    好的,找到了解决办法,代码如下:

    -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    
        UITouch *touch = [[event allTouches] anyObject];
    
        if ([touch view] == imageView) {
    
            CGPoint location = [touch locationInView: self.view];
    
            imageView.center = location;
    
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-27
      • 2017-11-14
      • 2017-11-25
      • 1970-01-01
      相关资源
      最近更新 更多