UILabel动画帧改变无视延迟

时间:2014-07-28 23:13:20

标签: objective-c uiview uilabel uiviewanimation

我有一个我显示/隐藏的UILabel。我想显示标签,暂停几秒钟并隐藏它。此代码不起作用。它会在动画结束后立即删除视图

-(void) show
{
    [UIView animateWithDuration:.5f delay:0.0f
                        options:UIViewAnimationOptionCurveEaseIn  animations:^{

                    CGRect newFrame = CGRectMake(0.0f, 64.0f, [UIScreen mainScreen].bounds.size.width, 44.0f);
                    self.frame = newFrame;

    }                completion:^(BOOL finished){

                            [self hideAndRemove];

    }];

}

-(void) hideAndRemove
{
    [UIView animateWithDuration:.5f delay:2.0f
                        options:UIViewAnimationOptionCurveEaseIn  animations:^{

        CGRect frame = CGRectMake(0.0f, 64.0f, [UIScreen mainScreen].bounds.size.width, 0.0f);
        self.frame = frame;

    }                completion:^(BOOL finished){

        // nothing

    }];
}

但是,如果我在帧上尝试其他动画,则延迟会起作用并且帧更改会被动画化:

-(void) show
{
    [UIView animateWithDuration:.5f delay:0.0f
                        options:UIViewAnimationOptionCurveEaseIn  animations:^{

                    CGRect newFrame = CGRectMake(0.0f, 64.0f, [UIScreen mainScreen].bounds.size.width, 44.0f);
                    self.frame = newFrame;

    }                completion:^(BOOL finished){

                            [self hideAndRemove];

    }];

}

-(void) hideAndRemove
{
    [UIView animateWithDuration:.5f delay:2.0f
                        options:UIViewAnimationOptionCurveEaseIn  animations:^{

        CGRect frame = CGRectMake(0.0f, 64.0f, [UIScreen mainScreen].bounds.size.width, 250.0f);
        self.frame = frame;

    }                completion:^(BOOL finished){

        // nothing

    }];
}

1 个答案:

答案 0 :(得分:0)

我不知道问题可能是什么,但我认为它来自不应该设置为0的帧高。

为什么不使用[UILabel setAlpha:0]来隐藏你的标签,[UILabel setAlpha:1]来显示它?它似乎比将帧高改为0更清晰,而且动画效果很好。

相关问题