我使用此代码来检测UIButton
和UIImageView
何时重叠:
CGPoint fingerPoint = [(UIPanGestureRecognizer*)sender locationInView:imageA.superview];
if (CGRectContainsPoint(imageA.frame, fingerPoint)) {
NSLog(@"Do something");
}
代码工作正常,但我有图像B,C,D,E。
如何循环它们的集合并将CGRectContainsPoint()
移动到该循环的主体中?
答案 0 :(得分:0)
NSArray* images = @[ imageA, imageB, imageC, imageD, imageE ];
for (UIImageView* image in images) {
CGPoint fingerPoint = [(UIPanGestureRecognizer*)sender locationInView:[image superview]];
if (CGRectContainsPoint(image.frame, fingerPoint)) {
// Do something.
}
}