2013-02-19 71 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