【问题标题】:Many UIView animation causing performance problem?许多 UIView 动画导致性能问题?
【发布时间】:2011-06-24 02:38:37
【问题描述】:

我有一个执行动画的对象...如果有许多(超过 25 个)对象同时在执行动画,则在拖动时会导致抖动...我在每个对象中使用以下代码创建动画。如何提高性能?

#define DEFAULT_ANIM_SPPED 0.6
#define INFINATE_VALUE 1e100f

- (void)startAnimating
{
    mBackgroundImageView.frame = mOriginalFrame;
    [UIView beginAnimations:nil context:nil];

    [UIView setAnimationRepeatAutoreverses:YES];
    [UIView setAnimationRepeatCount:INFINATE_VALUE];
    [UIView setAnimationDuration:DEFAULT_ANIM_SPPED];   

    CGRect tempFrame=mBackgroundImageView.frame;
    tempFrame.origin.y -= mAnimationOffset;
    mBackgroundImageView.frame=tempFrame;
    [UIView commitAnimations];
}

【问题讨论】:

    标签: iphone objective-c performance uiviewanimation


    【解决方案1】:

    不要为每个视图创建动画,而是尝试使用一个动画块来为多个视图设置动画,例如在它们的公共父视图中。我不确定它是否会为您的案例带来 25 个视图的足够改进。

    【讨论】:

    • 我不明白为什么在不涉及超类本身的情况下不能使子类动画化。在超类的动画块中更改子类的帧。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-02
    • 1970-01-01
    • 1970-01-01
    • 2019-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多