I have 5 UIImageViews animated around the screen. If you click and it meets the requirements, it will add 1 to your account using this:
self.score.text = @(self.score.text.integerValue + 1).stringValue;
But when the text in UILabel updated, all animations stop abruptly, and the remaining UIImageViews disappear. But the animation resumes after a few seconds, as if the images were becoming hidden. Code for animating images and changing images (they are the same for each):
- (void) squareOneMover { NSUInteger r = arc4random_uniform(3); [self.squareOne setHidden:NO]; CGPoint originalPosition = self.squareOne.center; CGPoint position = self.squareOne.center; originalPosition.y = -55; position.y += 790; [self.squareOne setCenter:originalPosition]; [UIView animateWithDuration:r + 3 delay:0.0 options:UIViewAnimationOptionAllowUserInteraction animations:^{ [self.squareOne setCenter:position]; } completion:^(BOOL complete) { if (complete) { [self squareOneColour]; [self squareOneMover]; } } ]; } - (void) squareOneColour { NSUInteger r = arc4random_uniform(5); [self.squareOne setImage:[self.colorArray objectAtIndex:r]]; }
Anyone have a solution? And if when changing text in UILabel it is supposed to stop the animation (I don’t know why they will do it), someone can provide a workaround to make the evaluation possible.
Edit: I created a button that will increment the integer score . This means that I can change the text in UILabel manually. The animation still stopped when the text changed.
Edit 2: Method for clicked event:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint touchLocation = [touch locationInView:self.view]; NSUInteger a = [self.colorArray indexOfObject:self.squareOne.image]; NSUInteger b = [self.iconColorArray indexOfObject:self.icon.image]; if ([self.squareOne.layer.presentationLayer hitTest:touchLocation]) { _squareOne.hidden = YES; } if (a!=b) { if (self.squareOne.hidden==YES) { NSLog(@"NO"); } } if (a==b) { if ([self.squareOne.layer.presentationLayer hitTest:touchLocation]) { self.score.text = @(self.score.text.integerValue + 1).stringValue; } } if ([self.squareTwo.layer.presentationLayer hitTest:touchLocation]) { _squareTwo.hidden = YES; } }
Looking at Matt, how could I revitalize a UIImageView by “changing its constraints”?
Limitations:
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-25-[btn1]-25-[btn2(==btn1)]-25-[btn3(==btn1)]-25-[btn4(==btn1)]-25-[btn5(==btn1)]-25-|" options:0 metrics:nil views:views]]; [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.squareOne attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:0.0 constant:-55.0]];
objective-c uitextfield animation uiimageview
Minestrone-Soup Nov 13 '14 at 23:59 2014-11-13 23:59
source share