开发者

[IOS SDK]- touchesBegan with specific object?

开发者 https://www.devze.com 2023-01-31 16:48 出处:网络
When I touch anywhere on screen touchesBegan event triggered. but I couldn\'t manage how if I touch specific object as like UIImageView?

When I touch anywhere on screen touchesBegan event triggered. but I couldn't manage how if I touch specific object as like 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];

}


Ok, found the solution, here is the code:

-(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;

    }

}
0

精彩评论

暂无评论...
验证码 换一张
取 消