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