2010-05-30 67 views
0

我在QuartzDemo示例應用程序中使用CGContextDrawPDFPage顯示了pdf頁面。CGContextDrawPDFPage上的圖像動畫

我想保持顯示此頁面,並在本頁面的頂部顯示圖像,就像它可以在iBooks應用程序中看到的一樣。

這是一本書,滑動圖像是一個書籤,當您要關閉本書時,它會滑入。

我通過DyingCactus加入此代碼(提示:IM新手到OBJ c和iPhone開發)如下:

在QuartzViewController.m,動畫開始顯示,但該視圖的動畫前滑動遠已完成,實際上我認爲動畫會在視圖滑開時繼續播放。

-(void)viewWillDisappear:(BOOL)animated 
{ 
    [self.quartzView setFrame:CGRectMake(150, -200, 100, 200)]; 
    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:1.0]; 
    [self.quartzView setFrame:CGRectMake(150, 0, 100, 200)]; 
    [UIView commitAnimations]; 
} 

如何在視圖消失之前保持視圖可見並完成動畫?

回答

0

我假設你正在修改Apple的QuartzDemo示例應用程序。

我現在能想到的最佳方式是,當顯示的視圖是PDF視圖時,用您自己的按鈕替換導航控制器上的後退按鈕。

您的自定義後退按鈕可以根據需要管理動畫並查看彈出序列。

只有這樣的煩惱是後退按鈕不再有左箭頭形狀。

以下是QuartzViewController.m需要作出的改變:

#import "QuartzImages.h" //<-- add this import 
... 
-(void)viewDidLoad 
{ 
    // Add the QuartzView 
    [scrollView addSubview:self.quartzView]; 

    //add custom back button if this is the PDF view... 
    if ([self.quartzView isKindOfClass:[QuartzPDFView class]]) 
    { 
     self.navigationItem.leftBarButtonItem = 
     [[UIBarButtonItem alloc] initWithTitle:@"QuartzDemo" 
           style:UIBarButtonItemStyleBordered 
           target:self 
           action:@selector(myBackButtonHandler:)]; 
    } 
} 

- (void)myBackButtonHandler:(id)sender 
{ 
    [self.quartzView setFrame:CGRectMake(150, -200, 100, 200)]; 
    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)]; 
    [UIView setAnimationDuration:1.0]; 
    [self.quartzView setFrame:CGRectMake(150, 0, 100, 200)]; 
    [UIView commitAnimations]; 
} 

- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context 
{ 
    [self.navigationController popViewControllerAnimated:YES]; 
}