CGContextDrawPDFPage 上的图像动画

发布于 2024-09-03 15:44:52 字数 661 浏览 13 评论 0原文

我在 QuartzDemo 示例应用程序中使用 CGContextDrawPDFPage 显示了一个 pdf 页面。

我想保持此页面显示,并从该页面顶部滑入图像,就像在 iBooks 应用程序中看到的那样。

这是一本书,滑动图像是一个书签,当你要合上书时,它会滑进去。

我通过 DyingCactus 添加了这段代码(提示:我是 obj c 和 iphone dev 的新手),如下所示:

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

如何保持视图可见并在视图消失之前完成动画?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

马蹄踏│碎落叶 2024-09-10 15:44:52

我假设您正在修改 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];
}

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];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文