Image animation over CGContextDrawPDFPage

Posted by BittenApple on Stack Overflow See other posts from Stack Overflow or by BittenApple
Published on 2010-05-30T11:02:57Z Indexed on 2010/05/30 13:22 UTC
Read the original article Hit count: 430

Filed under:
|
|

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?

© Stack Overflow or respective owner

Image animation over CGContextDrawPDFPage

Posted by BittenApple on Stack Overflow See other posts from Stack Overflow or by BittenApple
Published on 2010-05-30T18:20:50Z Indexed on 2010/05/30 18:22 UTC
Read the original article Hit count: 430

Filed under:
|
|

I'm modifying the QuartzDemo sample app from Apple.

In QuartzViewController.m I have modifications (by DyingCactus) which replac the back button and add a method to handle the back button press as follows:

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

I have a PNG image in resources folder called "bookmark.png" and would like to have that image animate as in animation in the example above. The image can be loaded in an UImageview or something and lets say that I have one called bookmark.

How do I call that instead of self.quartzview in this part of code:

[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]; 

© Stack Overflow or respective owner

Related posts about iphone

Related posts about animation