2011-01-10 17 views
0

私は背景画像とUIWebViewがautoresizeResizingMaskプロパティを介して方向変更に自動的にサイズ変更するように設定されたUIViewコントローラを持っています。これはシミュレータでスムーズに実行されますが、デバイス上でプレビューされると非常に遅くなります。UIViewの動作が遅いのはなぜですか?

ウェブビュー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]; 
} 

をしたのです。 1024x1024 72ppi PNG。

大変助かりました。ありがとう。

答えて

5

影は非常に高価です。 iOS 3.2以降では、CALayerに特別なプロパティがあり、shadowPathと呼ばれています。これは、シャドウの輪郭を定義するあらかじめ計算されたパスです。これにより、レイヤーは合成されたレイヤーのアルファチャンネルを使用してオンザフライでパスを生成する必要がなくなります。この行を追加すると多くの手助けをします:

projectView.layer.shadowPath = 
    [[UIBezierPath bezierPathWithRect:projectView.layer.bounds] CGPath]; 
関連する問題