2010-05-30 74 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]; 
}