我有一个包含 pdf 的 uiviewcontroller。
pdf 是在 viewcontroller 的上下文中绘制的,并且部分被顶部的导航栏和底部的标签栏覆盖(这就是我想要的)。
我想通过双击隐藏这两个栏并可视化完整的 pdf 页面。
问题是 pdf 的底部未绘制,当我隐藏底部 tabBar 时,这一事实变得明显(顶部导航栏的隐藏效果很好)。
我的问题是:隐藏底栏后如何在“完整”上下文中绘制 pdf?
(我已经试过用setNeedsDisplay
强制重绘了,但是隐藏栏后上下文还是一样的)
以下是绘制 pdf 页面的代码:
-(void)drawLayer:(CALayer*)layer inContext:(CGContextRef)ctx
{
CGContextSetRGBFillColor(ctx, 1.0, 1.0, 1.0, 1.0);
CGContextFillRect(ctx, self.bounds);
CGContextTranslateCTM(ctx, 0.0, self.bounds.size.height);
CGContextScaleCTM(ctx, 1.0, -1.0);
CGContextConcatCTM(ctx, CGPDFPageGetDrawingTransform(pdfPage,kCGPDFMediaBox,self.bounds, 0, true));
CGContextDrawPDFPage(ctx, pdfPage);
}
初始化条的代码(在 appdelegate 中):
tabBarController = [[UITabBarController alloc] init];
MagazineViewController *magazineViewController = [[MagazineViewController alloc] init];
NewsTableViewController *newsViewController = [[NewsTableViewController alloc] init];
VideoViewController *videoViewController = [[VideoViewController alloc] init];
UINavigationController *magazineNavigationController = [[UINavigationController alloc] initWithRootViewController:magazineViewController];
UINavigationController *newsNavigationController = [[UINavigationController alloc] initWithRootViewController:newsViewController];
UINavigationController *videoNavigationController = [[UINavigationController alloc] initWithRootViewController:videoViewController];
magazineNavigationController.navigationBar.tintColor = [UIColor blackColor];
newsNavigationController.navigationBar.tintColor = [UIColor blackColor];
videoNavigationController.navigationBar.tintColor = [UIColor blackColor];
NSArray *tabsArray = [NSArray arrayWithObjects:magazineNavigationController, newsNavigationController, videoNavigationController, nil];
tabBarController.viewControllers = tabsArray;
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
以及隐藏条的代码:
for (UINavigationController *controller in tabBarController.viewControllers) {
if(controller.navigationBar.topItem.title == @"Magazine") {
[controller setNavigationBarHidden:(!controller.navigationBar.hidden) animated:YES];
tabBarController.tabBar.hidden = !tabBarController.tabBar.hidden;
[self setNeedsDisplay];
return;
}
}
谢谢