开发者

-(void)touchesBegan (TO A SPECIFIED UIIMAGEVIEW)

开发者 https://www.devze.com 2023-03-09 09:36 出处:网络
Hi I want to make it so that if you touch an image that I put on the view the -(void)checkcollision happens. The -(void)checkcollision happens, but when I touch anything. How can I say it only works i

Hi I want to make it so that if you touch an image that I put on the view the -(void)checkcollision happens. The -(void)checkcollision happens, but when I touch anything. How can I say it only works if i touch a specified image. e.g. a pimple:

IBOutlet UIImageView *pimple;
@property (nonatomic, retain) UIImageView *pimple;

here is the touchesBegan code

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


    UITouch *myTouch = [[event allTouches] anyObject];
    [self checkcollision];
}


-(void)checkcollision {

  开发者_开发技巧  if (label.text = @"0") {
        label.text = @"1";
    }

    pimple.hidden = YES;
}


CGPoint point = [myTouch locationInView:pimple];
if ( CGRectContainsPoint(pimple.bounds, point) ) {
    ... Touch detected.
}

Alternatively you can consider gesture recognizers. You can use a tap recognizer for this case.


There are two options:

  1. Subclass UIImageView and define your own handler
  2. Check sender - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event and compare it to your UIImageView instance.
0

精彩评论

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

关注公众号