UILabel在两个文本字符串之间反复淡出

时间:2014-05-29 08:27:53

标签: ios objective-c uilabel fade repeat

我是iOS编程的新手......当用户点击按钮时,我正试图在单个标签内的两个文本字符串之间进行动画处理。

到目前为止 - 我似乎正在使用嵌套/多级块动画进行适当的渐弱工作。即使有UIViewAnimationOptionRepeat& UIViewAnimationOptionAutoreverse它拒绝连续重复(直到用户点击另一个按钮)。有任何想法吗?!提前谢谢!

- (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) {

                                                                                                         }]; }]; }]; }];
}

1 个答案:

答案 0 :(得分:0)

试试这个,

- (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];
    }];

}];
}