2010-07-07 49 views
0

我想知道如何在我的iPad應用程序中使用核心動畫創建a curl or peel effect on an image,但是由於我在學習API,因此我只理解移動,縮放和旋轉2D圖像的不同方式(包括3D變換)。我想在兩面都有圖像的小的單獨圖層(即精靈)上實現這種效果,因此當您剝離圖層時,會在背面上顯示圖像。我還需要控制圖層剝離的位置和角度。我在數學上很可怕,希望有人比我更聰明,可以幫助我,只要我至少能夠理解我提到的那些基本轉變。有什麼方法可以使用Core Animation創建捲曲或剝離動畫?

非常感謝智慧!

+1

鏈接上顯示「HOTLINKING PREVENTION IMAGE」。請將圖片上傳到我們可以看到的地方。 – kennytm 2010-07-07 14:09:43

+0

[可以重新使用iBooks應用程序僅使用Core Animation重現3D翻頁效果,還是需要使用OpenGL ES?](http://stackoverflow.com/questions/3189575/could-you-recreate -e-3d-page-turning-effect-seen-the-ibooks-app-using-only-c) – 2010-07-07 16:15:18

回答

1

在其中輕鬆地創建它是通過使用的UIView的類方法如下的唯一方法:

這一代碼進入了MyViewController.h文件中:

@interface MyViewController : UIViewController 
    { 
     UIImageView* imageView1; 
     UIImageView* imageView2; 
    } 
    @end 

此代碼那張MyViewController.m文件中:

@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 

由於在本例中,第e UIViewController以編程方式創建,使用「loadView」方法創建由視圖控制器管理的視圖和該視圖將管理的子視圖。我希望這有幫助。乾杯。

0

你可以在大多數情況下跳過數學,讓api處理所有事情。試試這個代碼:

- (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

謝謝布蘭登!我不確定UIModalTransitionStylePartialCurl是我正在尋找的功能,因爲它不能真正讓我像其他轉換允許我那樣完全控制動畫(即,我不能從任何角度捲曲頁面,也不能當我不想要它時,我可以隱藏捲曲)。更何況,這隻適用於全屏視圖,我正試圖在單個精靈上實現這種效果。你的想法? – BeachRunnerFred 2010-07-07 15:03:52

+0

糟糕,它看起來不像模態視圖適合您的需求。你說的對,UIModalTransitionStylePartialCurl在除了UIModalPresentationFullScreen表現風格之外的任何事物上都拋棄了異常。我完全沒有注意到這一點。 我不知道如何做其他任何方式的剝離過渡。抱歉。 – Brandon 2010-07-07 16:11:13

相關問題