开发者

Detect specific object with UITouch

开发者 https://www.devze.com 2023-01-15 12:00 出处:网络
HI . i am trying to move an UIImageView object with UITouch and have problem with the code how can i implement UITouch to detect only my UIImageView object ?

HI . i am trying to move an UIImageView object with UITouch and have problem with the code how can i implement UITouch to detect only my UIImageView object ?

**imageA it my UIImageView

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

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

    if ([toucheA view] == imageA) {
        CGPoint location = [toucheA locationInView:self];
        imageA.center = location;       

    }
}

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

    [self touchesBegan:touches withEvent:event];
    CGPoint postion = imageA.center;
    imageA.center = postion;
    postion.y = 230;
    imageA.center = postion;

}开发者_如何学C

but doesn't work !


I think you can make a custom UIImageView by subclassing and receive touch event you want inside the custom view.

Generally, the top most view will receiver the touch event. If the view process the touch event and doesn't pass the event to another view, then the others view behind it are impossible to receive any touch event. If the view cannot deal with the touch event, it will pass that by calling super's method.

0

精彩评论

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