首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >可以使用Core animation创建卷曲或剥离动画的一些方法是什么?

可以使用Core animation创建卷曲或剥离动画的一些方法是什么?
EN

Stack Overflow用户
提问于 2010-07-07 20:49:46
回答 2查看 475关注 0票数 0

我试图弄清楚如何使用核心动画在我的iPad应用程序中创建a curl or peel effect on an image,但当我学习应用程序接口时,我只了解移动、缩放和旋转2D图像(包括3D转换)的不同方式。我想在两面都有图像的小的,单独的层(即精灵)上实现这个效果,所以当你剥离这一层时,你在背面暴露了图像。我还需要控制图层剥离的位置和角度。我的数学很糟糕,我希望有比我更聪明的人能帮助我,只要我至少理解了我提到的那些基本的转换。

非常感谢您的智慧!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-07-08 00:29:31

轻松创建它的唯一方法是使用UIView的类方法,如下所示:

此代码位于MyViewController.h文件中:

代码语言:javascript
复制
 @interface MyViewController : UIViewController
    {
       UIImageView* imageView1;
       UIImageView* imageView2;
    }
  @end

下面的代码放在MyViewController.m文件中:

代码语言:javascript
复制
 @implementation MyViewController

    - (void) dealloc
    {
       [imageView2 release];
       [imageView1 release];

       [super dealloc];
    }

    - (void) loadView
    {
       self.view = [[UIView alloc] initWithFrame : CGRectMake (0, 0, 768, 1004)];

       UIImage* image1 = [[UIImage alloc] initWithContentsOfFile : @"image1.png"];
       UIImage* image2 = [[UIImage alloc] initWithContentsOfFile : @"image2.png"];

       imageView1 = [[UIImageView alloc] initWithImage : image1];
       imageView2 = [[UIImageView alloc] initWithImage : image2];

       [imageView1 setFrame : CGRectMake (0, 0, 768, 1004)];
       [imageView1 setFrame : CGRectMake (0, 0, 768, 1004)];

       [self.view addSubview : imageView1];

       [image2 release];
       [image1 release];
    }

    - (void) viewDidUnload
    {
       imageView2 = nil;
       imageView1 = nil;

       [super viewDidUnload];
    }

    - (void) touchesBegan : (NSSet*) touches withEvent : (UIEvent*) event
    {
       [UIView beginAnimations : nil context : nil];
       [UIView setAnimationCurve : UIViewAnimationCurveLinear];
       [UIView setAnimationDuration : 0.25];

       if (imageView1.superview != nil)
       {
          [UIView setAnimationTransition : UIViewAnimationTransitionCurlUp forView : self.view cache : YES];
          [imageView1 removeFromSuperview];
          [self.view addSubview : imageView2];
       }
       else
       {
          [UIView setAnimationTransition : UIViewAnimationTransitionCurlDown forView : self.view cache : YES];
          [imageView2 removeFromSuperview];
          [self.view addSubview : imageView1];
       }

       [UIView commitAnimations];
    }
 @end

在本例中,由于UIViewController是以编程方式创建的,因此使用方法"loadView“来创建由视图控制器管理的视图和该视图将管理的子视图。我希望这能帮到你。干杯。

票数 1
EN

Stack Overflow用户

发布于 2010-07-07 22:46:13

在大多数情况下,您可以跳过数学运算,让api处理所有事情。尝试以下代码:

代码语言:javascript
复制
- (IBAction)showPeelBack:(id)sender{
    FooController *controller = [[CreditsController alloc] initWithNibName:@"Foo" bundle:nil];
    // setup the stuff you want to display
    [controller setViewController: self];

    controller.modalPresentationStyle = UIModalPresentationFullScreen;
    controller.modalTransitionStyle = UIModalTransitionStylePartialCurl;

    // note: I'm using a nav controller here
    [[self navigationController] presentModalViewController:controller animated:YES];
    [controller release];
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3194777

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档