如何在for循环中与图像进行一般碰撞

发布于 2024-09-09 18:53:46 字数 953 浏览 2 评论 0原文

碰撞,但它只适用于 1 个图像,

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
     UITouch *touch = [touches anyObject]; 
     CGPoint p = [touch locationInView:self.view]; 
     if (CGRectContainsPoint(CGRectMake(myImage1.frame.origin.x, myImage1.frame.origin.y, myImage1.frame.size.width, myImage1.frame.size.height ), p)) 
     { 
         [pieMenu showInView:self.view atPoint:p]; 
     }
} 

这适用于

[self addImageSubViewAtX:160.0 atY:190.0];

OR

[self addImageSubViewAtX:90.0 atY:140.0];

,但不能一起使用,

这是您定义的方法

- (void)addImageSubViewAtX:(CGFloat)x atY:(CGFloat)y {
    CGRect myImageRect1 = CGRectMake(x, y, 30.0f, 30.0f); 
    myImage1 = [[UIImageView alloc] initWithFrame:myImageRect1]; 
    [myImage1 setImage:[UIImage imageNamed:@"status_finish.gif"]]; 
    [self.view addSubview:myImage1];        
}

collison but its only working for 1 image

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
     UITouch *touch = [touches anyObject]; 
     CGPoint p = [touch locationInView:self.view]; 
     if (CGRectContainsPoint(CGRectMake(myImage1.frame.origin.x, myImage1.frame.origin.y, myImage1.frame.size.width, myImage1.frame.size.height ), p)) 
     { 
         [pieMenu showInView:self.view atPoint:p]; 
     }
} 

this will work either for

[self addImageSubViewAtX:160.0 atY:190.0];

OR

[self addImageSubViewAtX:90.0 atY:140.0];

but not together

this is method defined by you

- (void)addImageSubViewAtX:(CGFloat)x atY:(CGFloat)y {
    CGRect myImageRect1 = CGRectMake(x, y, 30.0f, 30.0f); 
    myImage1 = [[UIImageView alloc] initWithFrame:myImageRect1]; 
    [myImage1 setImage:[UIImage imageNamed:@"status_finish.gif"]]; 
    [self.view addSubview:myImage1];        
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ㄖ落Θ余辉 2024-09-16 18:53:46

我建议让一个方法接收一些参数,因为它们并不完全相同

- (void)addImageSubViewAtX:(CGFloat)x atY:(CGFloat)y {
  CGRect myImageRect1 = CGRectMake(x, y, 30.0f, 30.0f); 
  myImage1 = [[UIImageView alloc] initWithFrame:myImageRect1]; 
  [myImage1 setImage:[UIImage imageNamed:@"status_finish.gif"]]; 
  [self.view addSubview:myImage1];

}

,然后调用它两次: [self addImageSubViewAtX:160.0 atY:190.0] 和 [self addImageSubViewAtX:90.0 atY:140.0]

I suggest to make a method receive some parameter because they are not absolutely the same

- (void)addImageSubViewAtX:(CGFloat)x atY:(CGFloat)y {
  CGRect myImageRect1 = CGRectMake(x, y, 30.0f, 30.0f); 
  myImage1 = [[UIImageView alloc] initWithFrame:myImageRect1]; 
  [myImage1 setImage:[UIImage imageNamed:@"status_finish.gif"]]; 
  [self.view addSubview:myImage1];

}

and then you call it 2 times : [self addImageSubViewAtX:160.0 atY:190.0] and [self addImageSubViewAtX:90.0 atY:140.0]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文