Ich habe den folgenden Code, um festzustellen, ob eine Berührung innerhalb einer Bildansicht in meiner Tabellenzelle ist. Es funktioniert jedoch nicht. Ich habe die beiden mit CGRectContainsPoint verglichen, aber es funktioniert nicht. Hier ist der Code:Vergleichen einer UITouch-Position mit UIImageView-Rechteck
-(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");
}
}
Danke für die Hilfe!
Erweiterung: 'CGPoint touchLocation = [touch locationInView: self]; if (CGRectContainsPoint (myImageView.frame, touchLocation)) '' funktioniert nur, wenn 'myImageView' eine direkte Unteransicht von' self' –
ist, die Joaos Kommentar erweitert. Sie können den Frame einer Unteransicht relativ zur Superview (oder einer beliebigen Ansicht) mit 'CGRect aufrufen frameRelativeToView = [myImageView convertRect: myImageView.bounds toView: self] ' – chazzwozzer