There is a game with a playing field:

NSInteger width = self.view.bounds.size.width / 6; UIView* gameDeskView = [[UIView alloc] initWithFrame:CGRectMake(self.view.bounds.origin.x + width/2, (self.view.bounds.size.height-width*5)/2, width * 5, width * 5)]; 

The field is filled with cells:

 for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { x = width * j; y = width * lineCount; UIView* cell = [[UIView alloc] initWithFrame:CGRectMake(x, y, self.gameDeskView.frame.size.width / 5, self.gameDeskView.frame.size.width / 5)]; self.cell = cell; UIGraphicsBeginImageContext(cell.frame.size); [[UIImage imageNamed:@"1.png"] drawInRect:cell.bounds]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); cell.backgroundColor = [UIColor colorWithPatternImage:image]; [gameDeskView addSubview:cell]; rowCount ++; } lineCount ++; } } 

And there are numbers that I drag on the field.
I need to make a check: if the number is on the field, then we leave it on the field, and if the number is not on the field, then it flies home:

 -(void) draggCancel { if (![ _gameDeskView pointInside:_view1.center withEvent:nil]) { [UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^ { self.view1.center = CGPointMake(110 , 590); } completion:^(BOOL finished) {}]; }else{ } } 

And everything works, but for some reason the figure sees the coordinates of the field are not those that are set, but as if the field is located ( 0,0,self.view.bounds.size.width / 6,self.view.bounds.size.width / 6 ).

How to fix it? Thank you in advance.

    1 answer 1

    For tracking, you can use the methods:

     CGRectContainsPoint(someView.frame, draggingView.center) CGRectContainsRect(someView.frame, draggingView.frame) CGRectIntersectsRect(someView.frame, draggingView.frame) 

    for transliteration coordinates, UIView has methods:

     - (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view; - (CGPoint)convertPoint:(CGPoint)point fromView:(UIView *)view; - (CGRect)convertRect:(CGRect)rect toView:(UIView *)view; - (CGRect)convertRect:(CGRect)rect fromView:(UIView *)view;