I'm new to iOS programming...I'm trying to animate the transition between two text strings within a single label when the user taps a button.
So far - I seem to have the fading working suitably using nested / multistage block animations. Yet even with UIViewAnimationOptionRepeat
& UIViewAnimationOptionAutoreverse
it refuses to repeat itself continuously (until the user taps another button). Any ideas?! Thanks in advance!
- (IBAction)FadeButtonPress:(id)sender {
[UIView animateWithDuration:1.0
delay:0
options: UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse
animations:^{ _FadeLabel.text = @"AAAA";
[_FadeLabel setAlpha:1.0f ]; }
completion:^(BOOL finished) {
[UIView animateWithDuration:1.0
delay:0
options: nil
animations:^{ [_FadeLabel setAlpha:0.0f]; }
completion:^(BOOL finished) {
[UIView animateWithDuration:1.0
delay:0
options: nil
animations:^{_FadeLabel.text = @"BBBB";
[_FadeLabel setAlpha:1.0f ]; }
completion:^(BOOL finished) {
[UIView animateWithDuration:1.0
delay:0
options: nil
animations:^{ [_FadeLabel setAlpha:0.0f]; }
completion:^(BOOL finished) {
}]; }]; }]; }];
}
Try this,
- (IBAction)FadeButtonPress:(id)sender {
[UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveLinear animations:^{
if ([_labe.text isEqualToString:@"Text 1"]) {
[_labe setText:@"Text 2"];
} else {
[_labe setText:@"Text 1"];
}
[self.labe setAlpha: 1];
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.5 animations:^{
[self.labe setAlpha: 0];
} completion:^(BOOL finished) {
[self FadeButtonPress:sender];
}];
}];
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.