我有以下代码来确定触摸是否在我的表格单元格中的图像视图内。然而,它不起作用。我使用CGRectContainsPoint进行了比较,然而它也不起作用。这是代码:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// Declare the touch and get it's location
UITouch *touch = [touches anyObject];
CGPoint touchLocation = [touch locationInView:self];
if (CGRectContainsPoint(myImageView.frame, touchLocation))
{
NSLog(@"Tapped image view");
}
}
感谢您的帮助!
myImageView
жҳҜself
зҡ„зӣҙжҺҘеӯҗи§Ҷеӣҫж—¶пјҢжү©еұ•CGPoint touchLocation = [touch locationInView:self]; if (CGRectContainsPoint(myImageView.frame, touchLocation))
жүҚжңүж•ҲгҖӮ - João PortelaCGRect frameRelativeToView = [myImageView convertRect:myImageView.bounds toView:self]
获取子视图相对于父视图(或任何视图)的框架。 - chazzwozzer