I have a UIView animateWithDuration
(in a method being called by a button) that animates a UIImageViews
. The important code before the animation code: (the title is appropriate, just keep reading)
//Sets _squareOneNumber to 0 (this is going to be the changing value)
_squareOneNumber = 0;
Basically the animation code just allows user interaction and animates the image to down the screen at a random pace.
But, it's the completion block that is killing me (don't worry about a
and b
):
if (self.squareOneNumber==0) {
if (a==b) {
[self gameOverImagePutter];
NSLog(@"One wasn't pressed");
}
}
The value of _squareOneNumber
changes to 1 if it is pressed.
//In touchesBegan method
UITouch *touch = [touches anyObject];
CGPoint touchLocation = [touch locationInView:self.view];
if ([self.squareOne.layer.presentationLayer hitTest:touchLocation]) {
[_squareOne setHidden:YES];
_squareOneNumber = 1;
}
The completion block should call gameOverImagePutter
if squareOne
wasn't pressed (squareOneNumber=0
) and a==b
. But it is always called when squareOne
is pressed (squareOneNumber=1
). To me, the code should work fine. But I think the issue is that squareOneNumber
isn't getting updated even though its value has changed.
So basically this is my question:
- how to I get the code to work?
- why isn't
squareOneNumber
realizing it's value has changed?