为什么我的UIView表现得很迟钝?

gar*_*uan 0 cocoa-touch uiwebview calayer uiview

我有一个UIView控制器,它有一个背景图像和一个UIWebView设置,可以通过autoresizeResizingMask属性自动调整方向更改.它在模拟器中运行平稳,但在设备上预览时非常缓慢.

我很少使用Web视图CALayer来创建边框和阴影,当我评论这些部分时,它运行得更顺畅.当玩CALayer(我怀疑)或者我是否错误地实现了这些部分时,这只是该课程的标准吗?

这是视图确实加载方法

// 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];
}
Run Code Online (Sandbox Code Playgroud)

背景图像也很大.1024x1024 72ppi PNG.

任何帮助非常感谢.谢谢.

Nat*_*ror 5

绘制阴影非常昂贵.在iOS 3.2及更高版本中,CALayer调用了一个特殊属性shadowPath.它是一个预先计算的路径,用于定义阴影的轮廓.这使得图层不必使用图层的合成Alpha通道即时生成路径.添加此行应该有很多帮助:

projectView.layer.shadowPath = 
  [[UIBezierPath bezierPathWithRect:projectView.layer.bounds] CGPath];
Run Code Online (Sandbox Code Playgroud)