![](/img/trans.png)
[英]Which method gets called when we double tap the home button and send the app in the background?
[英]Lag with CALayer when double tap on the home button
当我用CALayer放置阴影等时,双击主屏幕按钮查看正在运行的任务时,我的应用程序滞后了。 我没有任何其他滞后,只需双击即可。
我调用此方法20次以放置20张图像:
- (UIView *)createImage:(CGFloat)posX posY:(CGFloat)posY imgName:(NSString *)imgName
{
UIView *myView = [[UIView alloc] init];
CALayer *sublayer = [CALayer layer];
sublayer.backgroundColor = [UIColor blueColor].CGColor;
sublayer.shadowOffset = CGSizeMake(0, 3);
sublayer.shadowRadius = 5.0;
sublayer.shadowColor = [UIColor blackColor].CGColor;
sublayer.shadowOpacity = 0.8;
sublayer.frame = CGRectMake(posX, posY, 65, 65);
sublayer.borderColor = [UIColor blackColor].CGColor;
sublayer.borderWidth = 2.0;
sublayer.cornerRadius = 10.0;
CALayer *imageLayer = [CALayer layer];
imageLayer.frame = sublayer.bounds;
imageLayer.cornerRadius = 10.0;
imageLayer.contents = (id) [UIImage imageNamed:imgName].CGImage;
imageLayer.masksToBounds = YES;
[sublayer addSublayer:imageLayer];
[myView.layer addSublayer:sublayer];
return myView;
}
除此以外,我已经注释了我所有的代码,所以我确定滞后来自这里。 另外,我已经使用“分配”工具进行了检查,我的应用程序从未超过1Mo。 当我只放置没有阴影等的图像时,一切正常。
也尝试在shadowPath
上设置shadowPath
。 由于您的图层上有圆角,因此它必须是圆角的rect。
如果没有阴影路径,则CALayer必须计算其绘制位置以及阴影放置位置。 这对动画性能有很大影响。
使用CALayers提高性能的另一种方法是将shouldRasterize
属性设置为YES。 这会将图层内容存储为位图,并防止其必须重新渲染所有内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.