English 中文(简体)
我的《智囊团》是jer的,我如何能够优化以下法典?
原标题:My UIView animation is jerky - how can I optimize the following code?

On the simulator, my animation method runs smoothly. Unfortunately it seems to be very jerky running on an iPhone 4.

我不会百分之百地肯定做 an事的最佳和最快的方式——因此,对于我如何能够优化或彻底修改我的法典以加快这一 an升表示最赞赏!

<>说明:

它已经站在主线上,这样,派遣国——阿辛(派遣国——目标_主要——(频率))就会毫不相干或毫无帮助?

是否有办法预先缓冲这一估计?

是否有办法看看,哪一部分法典在做大部分放慢?

在延期方面,只有大约3或4个意见。 观点。

I ve与Os编辑。

- (void)extendWithAnimation:(BOOL)animated; {

    isExtended = YES;
    extensionView.hidden = NO;
    topShadowView.hidden = NO;

    topShadowView.frame = CGRectMake(0, defaultHeight, topShadowView.frame.size.width, topShadowView.frame.size.height);
    topShadowView.layer.bounds = CGRectMake(0, 0, topShadowView.frame.size.width, 0);
    extensionView.frame = CGRectMake(0, defaultHeight - 8, DEVICE_WIDTH, extensionHeight + 8);
    extensionView.layer.bounds = CGRectMake(0, 0, DEVICE_WIDTH, 0);

    for (UIView *view in extensionView.subviews) {
        view.transform = CGAffineTransformMakeTranslation(0, -(extensionHeight+8));
    }

    dispatch_async(dispatch_get_main_queue(), ^{

        if (animated) {
            [UIView beginAnimations:nil context:nil];
            [UIView setAnimationDuration:0.3];
            [UIView setAnimationDelegate:self];
        }

        extensionView.layer.bounds = CGRectMake(0, 0, DEVICE_WIDTH, extensionHeight + 8);
        topShadowView.layer.bounds = CGRectMake(0, 0, topShadowView.frame.size.width, extensionHeight + 8);

        for (UIView *view in extensionView.subviews) {
            view.transform = CGAffineTransformIdentity;
        }

        if (animated) {
            [UIView commitAnimations];
        }
    });   
}

<>Solution:

Solved (thanks Aaron!).

Rendered shadows kill animation big time! Don t use any core graphics shadow properties if you re planning on animating - in my case just a few shadows reduced the frame rate three fold.

最佳回答
  1. Well, if the code is already on the main queue then using dispatch_async is only going to have overhead.
  2. I don t know if this will help (I kind of doubt it), but you might try using [UIView animateWithDuration:.3 animations:{ code... }];
  3. In my past attempts to deal with shadows they ve tended to have a pretty big performance hit. You might consider leaving shadows and layers alone and instead create a resizable shadow PNG that you can use in a UIImageView placed behind the the view you want shadowed.
问题回答

通过文书(从时间简介开始)操作你的代码。 在估算过程中,最需要什么时间?

一旦了解情况,也通过核心估算工具进行,并能够从外部筛选和不可选取内容上进行取证。 这将有助于孤立共同的图表问题。

我也注意到你提到影子。 如果你使用CAL子的影子,这就有可能杀害你的工作。 但是,我们需要更多的信息,才能真正做到这一点。





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签