2013-02-19 73 views
0

我有子類的UINavigationController的添加上方法viewDidApper陰影:從UINavigationController的是這樣的:我的投影在自己重繪?

- (void)viewDidAppear:(BOOL)animated 
{ 
    // Add shadow to Navigation Bar 
    CAGradientLayer *newShadow = [[CAGradientLayer alloc] init]; 
    newShadow.shadowColor = [[UIColor blackColor] CGColor]; 
    newShadow.shadowOffset = CGSizeMake(0.0f, 4.0f); 
    newShadow.shadowOpacity = 1.0f; 
    CGRect shadowPath = CGRectMake(self.navigationBar.layer.bounds.origin.x - 10, self.navigationBar.layer.bounds.size.height - 6, self.navigationBar.layer.bounds.size.width + 20, 5); 
    newShadow.shadowPath = [UIBezierPath bezierPathWithRect:shadowPath].CGPath; 
    newShadow.shouldRasterize = YES; 
    self.navigationBar.clipsToBounds = NO; 
    [self.navigationBar.layer addSublayer:newShadow]; 
    [super viewDidAppear:animated]; 
} 

當我在ModalViewController使用NavigationController,陰影重畫一遍又一遍。

回答

2

因爲每次出現視圖時都會調用- viewDidAppear:方法。您可能希望將此代碼移到- viewDidLoad方法中。

+0

謝謝,現在不要重漆,而是在不正確的位置塗上陰影,就像2毫米。 – Montecorte 2013-02-19 16:54:50