如何在for循环中与图像进行一般碰撞
碰撞,但它只适用于 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议让一个方法接收一些参数,因为它们并不完全相同
,然后调用它两次:
[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
and then you call it 2 times :
[self addImageSubViewAtX:160.0 atY:190.0] and [self addImageSubViewAtX:90.0 atY:140.0]