为什么我的UIView行为缓慢?
问题描述:
我有一个UIView控制器有一个背景图像和一个UIWebView设置为通过autoresizeResizingMask
属性自动调整方向更改的大小。它在模拟器中运行平稳,但在设备上预览时非常缓慢。为什么我的UIView行为缓慢?
我使用web视图CALayer
的一小部分来创建边框和阴影,当我评论这些部分时,它运行得更顺畅。这是否仅仅是玩CALayer视图(我怀疑)还是我错误地实现了这些部分?
这里的景色确实load方法
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
NSLog(@"Web project View Controller");
[super viewDidLoad];
UIImageView *bg = [[UIImageView alloc] initWithFrame:self.view.bounds];
bg.contentMode = UIViewContentModeCenter;
bg.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
bg.image = [UIImage imageNamed:@"fuzzyhalo.png"];
[self.view addSubview:bg];
projectView = [[UIWebView alloc] initWithFrame:self.view.bounds];
projectView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
projectView.layer.backgroundColor = [UIColor blackColor].CGColor;
projectView.layer.shadowColor = [UIColor blackColor].CGColor;
projectView.layer.shadowOpacity = 1.0;
projectView.layer.shadowRadius = 5.0;
projectView.layer.shadowOffset = CGSizeMake(0, 0);
projectView.layer.borderColor = [UIColor blueColor].CGColor;
projectView.layer.borderWidth = 2.0;
CGRect newFrame = self.view.bounds;
newFrame.origin.x = 40;
newFrame.origin.y = 40;
newFrame.size.width = newFrame.size.width - 80;
newFrame.size.height = newFrame.size.height - 80;
projectView.frame = newFrame;
[self.view addSubview:projectView];
}
背景图片也相当大。 1024x1024 72ppi PNG。
任何帮助非常感谢。谢谢。
答
阴影是非常昂贵的绘制。在iOS 3.2和更高版本中,CALayer
上有一个特殊属性,称为shadowPath
。这是一个预定义的路径,用于定义阴影的轮廓。这使得图层无需使用图层的合成Alpha通道即时生成路径。添加这条线应该有很大帮助:
projectView.layer.shadowPath =
[[UIBezierPath bezierPathWithRect:projectView.layer.bounds] CGPath];