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 时,阴影会一遍又一遍地重绘。

4

1 回答 1

2

因为- viewDidAppear:每次视图出现时都会调用该方法。您可能希望将此代码移动到- viewDidLoad方法中。

于 2013-02-19T16:31:25.343 回答