1

我有一个包含 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;
        }
    }

谢谢

4

2 回答 2

0

问题出在隐藏条形的代码中,这里:

[controller setNavigationBarHidden:(!controller.navigationBar.hidden) animated:YES];
tabBarController.tabBar.hidden = !tabBarController.tabBar.hidden;

第一行是一个帮助方法,它为您删除导航栏 - 所以它很好地将自己从视图中删除。第二行只是更改“隐藏”属性 - 所以它不会很好地移除自己。

为了让标签栏隐藏得很好并且不剪裁你的上下文是调整它的框架。这是一个很好的例子,或者您可以在标签栏上设置框架,例如:

与第二行交换

tabBarController.tabBar.frame = CGRectMake(0,0,0,0);
于 2010-11-17T18:43:54.937 回答
-1

NSLog self.bounds,这是一个不错的工具箱功能:

-(NSString*)getStringFromCGRect:(CGRect)rect WithLabel:(NSString*)idName
{


return [NSString stringWithFormat:@">%@\nx:%f\ny:%f\nWidth:%f\nHeight:%f\n\n",idName,rect.origin.x,rect.origin.y,rect.size.width,rect.size.height];
}

我猜想您的界限将是您的视图大小 - 您的工具栏高度,如果不是您CALayer在创建绘图类时配置任何 's 吗?

于 2010-11-17T16:51:04.690 回答