ios - CGRectContainsPoint doesn't return YES but on simulator the point is in the image -


in viewdidload making imageview called deepfryingbasket. can move basket finger left , right not or down. second image have 1 french frie falling down screen. if frie , basket collide, frie should disappear looks falls in basket. thats why have nstimer fires every 0.01 sec collisiondetection method.

the problem when catch french frie basket frie doesn't disappear. sure collisiondetection method called compiler never gets in if-statement , don't know why. appreciated!

- (void)viewdidload {     [super viewdidload];     deepfryingbasket =[[uiimageview alloc] initwithframe:cgrectmake(110,468,100,80)];     deepfryingbasket.image = [uiimage imagenamed:@"deepfryingbasket"];     [self.view addsubview:deepfryingbasket];     collisiondetection = [nstimer scheduledtimerwithtimeinterval:0.01 target:self selector:@selector(collisiondetection) userinfo:nil repeats:yes];     [collisiondetection fire]; }  -(void)collisiondetection{     if (cgrectcontainspoint (frenchfrie.frame, deepfryingbasket.center)){         [frenchfrie removefromsuperview];         points = points + 1;         dropped = dropped +1;     } } 

i move basket following code:

-(void)touchesmoved:(nsset *)touches withevent:(uievent *)event {     uitouch *touch = [[event alltouches] anyobject];     touchlocation = [touch locationinview:self.view];     frame = deepfryingbasket.frame;     if (cgrectcontainspoint(frame, touchlocation)){         deepfryingbasket.center = cgpointmake(touchlocation.x, deepfryingbasket.center.y);     } } 

edit: tried adding

    deepfryingbasket.userinteractionenabled = yes; 

but didn't change much. found out while french frie falls animation, origin of image didn't change. why isn't changing? noticed when move basket it's center.x moves along finger. move french frie following code:

-(void)letfrenchfriefall {     [uiview animatewithduration:10.0f delay:0 options:uiviewanimationoptioncurvelinear animations:^{     frenchfrie.frame = cgrectmake(randomx, (int)[[uiscreen mainscreen] bounds].size.height + 40, frenchfrie.frame.size.width, frenchfrie.frame.size.height);     } completion:^(bool finished){         [frenchfrie removefromsuperview];     }]; } 

ok found answer own question: while imageview moving due animation, x- , y-coordinate set place animation ends; reason impossible it's location

frenchfrie.frame 

you can use

frenchfrieframe = [[frenchfrie.layer presentationlayer] frame]; 

to frame displayed. don't forget include quartzcore framework , import it.

#import <quartzcore/quartzcore.h> 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -