2011-01-10 118 views
0

我有一個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。

任何幫助非常感謝。謝謝。

回答

5

陰影是非常昂貴的繪製。在iOS 3.2和更高版本中,CALayer上有一個特殊屬性,稱爲shadowPath。這是一個預定義的路徑,用於定義陰影的輪廓。這使得圖層無需使用圖層的合成Alpha通道即時生成路徑。添加這條線應該有很大幫助:

projectView.layer.shadowPath = 
    [[UIBezierPath bezierPathWithRect:projectView.layer.bounds] CGPath];