UIView将动画与不同的持续时间相结合

时间:2014-11-20 09:35:07

标签: ios objective-c animation uiview uiviewanimation

我想在我的视图上为alpha更改和框架更改设置动画。 Catch是我想要在更改帧之前结束alpha更改。 目前我正在做这样的事情同时实现两者:

UIView *someview = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
        [self.view addSubview:someview];
        someview.alpha = 0.0f;
        [UIView animateWithDuration:1 animations:^{
            self.view.alpha = 1.0f;
            self.view.frame = CGRectMake(200, 200, 100, 100);
        }];

2 个答案:

答案 0 :(得分:1)

我认为你应该替换它:

[UIView animateWithDuration:1 animations:^{
    self.view.alpha = 1.0f;
    self.view.frame = CGRectMake(200, 200, 100, 100);
}];

为:

[UIView animateWithDuration:1 animations:^{
    self.view.alpha = 1.0f;
}];
[UIView animateWithDuration:1.4 animations:^{
    self.view.frame = CGRectMake(200, 200, 100, 100);
}];

答案 1 :(得分:0)

如果您想在动画后执行任何更改,您应该使用完成处理程序

进行animateWithDuration
[UIView animateWithDuration:1 animations:^{
        self.view.alpha = 1.0f;
        self.view.frame = CGRectMake(200, 200, 100, 100);
    }];

将以上代码替换为下面的代码

[UIView animateWithDuration:1.0 animations:^{
    self.view.alpha = 1.0f;
} completion:^(BOOL finished) {
    [UIView animateWithDuration:1 animations:^{
        self.view.frame = CGRectMake(200, 200, 100, 100);
    }];
}];

在此块中,当完成帧动画时,将发生第一次alpha动画

相关问题