views:

196

answers:

1

I have a pdf page displayed with CGContextDrawPDFPage in QuartzDemo sample application.

I want to keep this page shown and have an image slide in from top over this page, just as it can be seen in the iBooks application.

It's a book, the sliding image is a bookmark that slides in when you are about to close the book.

I added this code by DyingCactus (hint: im a newbie to obj c and iphone dev) as follows:

In QuartzViewController.m, the animation starts to show but the view slides away before the animation is finished, in fact I think the animation goes on while the view is sliding away.

-(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];  
}

How can I keep the view visible and finish the animation before view disappears?

A: 

I assume you're modifying the QuartzDemo sample app from Apple.

Best way I can think of right now is to replace the back button on the navigation controller with your own button when the view being shown is the PDF view.

Your custom back button can then manage the animation and view popping sequence as needed.

Only annoyance with this is that the back button no longer has a left-arrow shape.

Here are the changes needed in 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];
}
DyingCactus