繁体   English   中英

UIView子视图的不同动画持续时间

[英]Different animation duration for subviews of an UIView

我有以下代码

[UIView animateWithDuration:2 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{

            mainPage.frame=CGRectMake(0, -[UIScreen mainScreen].bounds.size.width,[UIScreen mainScreen].bounds.size.height,[UIScreen mainScreen].bounds.size.width);

        } completion:nil];

有什么方法可以控制mainPage子视图的动画持续时间。

您可以使用UIView:animateKeyframesWithDuration然后使用UIView:addKeyframeWithRelativeStartTime设置其开始时间和持续时间

[UIView animateKeyframesWithDuration:2 delay:0 options:0 animations:^{
    [UIView addKeyframeWithRelativeStartTime:0.32 relativeDuration:0.68 animations:^{
        view.frame = frame;
    }];
    [UIView addKeyframeWithRelativeStartTime:0.5 relativeDuration:1 animations:^{
        subview.frame = frame2;
    }];
} completion:^(BOOL finished) {
}];

如果希望子视图以不同的持续时间进行动画处理,则需要分别对每个子视图进行动画处理。 您可以遍历mainPage.subviews数组并发出animateWithDuration:delay:options:animations:completion:依次调用每个子视图,每个子视图具有不同的持续时间。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM