1

我有一個包含pdf的uiviewcontroller。在uitabbarcontroller中繪製pdfpage

pdf是在viewcontroller的上下文中繪製的,部分由導航欄頂部和底部的tabbar(這是我想要的)覆蓋。

我想用雙擊來隱藏兩個酒吧,並可視化完整的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); 

}

的代碼,在itializes條(在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; 
     } 
    } 

感謝

回答

-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

+0

不錯的功能,但它不會透露在這種情況下很多。 – Brandon 2010-11-17 18:30:43

+0

在我看來,dunders dv – 2010-11-17 21:58:01

+0

rect的大小是正確的(320 x 460),但pdf仍然被裁剪。我沒有配置任何CALayer,但現在我試圖繪製ovverriding - (void)drawRect:(CGRect)r但結果是一樣的 – Giovanni 2010-11-18 10:32:49

0

的問題是在隱藏你的酒吧,這裏的代碼:

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

第一行是一個輔助方法,它消除了你的導航欄 - 所以從視野很好刪除自身。 第二行只是更改'隱藏'屬性 - 所以它不會很好地移除它本身。

爲了得到很好的標籤欄隱藏和不削減你的上下文是調整其框架。這裏有一個nice example,或者你可以設置你喜歡標籤欄上的框架:

交換與第二線

tabBarController.tabBar.frame = CGRectMake(0,0,0,0); 
+0

http://meta.stackexchange.com/questions/19268/how-should-down-voting-be-used – 2010-11-18 00:30:40

+0

謝謝,以動畫效果良好爲例,但pdf仍被無形底欄限制。 – Giovanni 2010-11-18 10:35:31