Я использую два UIImageViews, я добавил к каждому UIImageView под просмотр (UIView). Я использую CGRectIntersectsRect для обнаружения столкновения, но не работает. Поэтому у меня есть:CGRectIntersectsRect of subviews
Это первый UIImageView
hand = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 13.5, 176)];
[hand setImage:[UIImage imageNamed:@"hand0.png"]];
[hand setContentMode:UIViewContentModeScaleAspectFit];
/// Add SUBVIEW which needs to be detected for collision
hView = [[UIView alloc]initWithFrame:CGRectMake(3, 12, 7, 10)];
[hView setBackgroundColor:[UIColor redColor]];
[hand addSubview:hView];
[hand bringSubviewToFront:hView];
hand.center = self.view.center;
[self.view addSubview:hand];
А вот второй UIImageView
ball = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 33.5, 176)];
[ball setImage:[UIImage imageNamed:@"ball0.png"]];
[ball setContentMode:UIViewContentModeScaleAspectFit];
/// Add SUBVIEW to detect for collision
bView = [[UIView alloc]initWithFrame:CGRectMake(3, 155, 28, 10)];
[bView setBackgroundColor:[UIColor greenColor]];
[ball addSubview:bView];
[ball bringSubviewToFront:bView];
ball.center = self.view.center;
[self.view addSubview:ball];
И вот мой код для обнаружения столкновений, которая проходит каждый второй.
- (void)checkCollision
{
if (CGRectIntersectsRect(bView.frame, hView.frame)) {
//do something here
}
}
Любые идеи, почему это не обнаруживает столкновение? Единственное, что я имею в виду, это то, что hView и bView являются областями UIImageView.
большое вам спасибо –