2010-09-08 114 views
5

我試圖在窗口中激發一個頁面捲曲過渡與UIImageView。此代碼位於我的主要init方法中:iPhone頁面捲曲過渡動畫

[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationDuration:1.5]; 
[UIView setAnimationDelay:delay]; 
[UIView setAnimationBeginsFromCurrentState:YES]; 
[UIView setAnimationDidStopSelector:@selector(animCompleteHandler:finished:context:)]; 
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:splashImage cache:YES]; 

splashImage.frame = CGRectMake(-320, 0, 10, 10); 
//[splashImage removeFromSuperview]; 

[UIView commitAnimations]; 

圖像動畫化位置和大小,但不捲曲。如果我取消對removeFromSuperView的評論,它會立即消失。有任何想法嗎?

UPDATE:

是否更改了代碼,以便它使用拉爾斯觸發動畫,包括動畫和回調的fantasticlly簡潔的方式...

[UIView animateWithDuration:1.5 
         delay:delay 
        options: UIViewAnimationTransitionCurlUp 
       animations:^{splashImage.alpha = 0;} 
       completion:^(BOOL finished){[splashImage removeFromSuperview];} 
]; 

不幸的是,頁面捲曲只是不會發生。它確實褪色。

我不確定這是否與語法有關,或者SplashImage是我的主視圖的UIWindow對象中的UIImageView類。也許它需要在UIView才能創建轉換。

回答

8

試着這麼做:

[UIView transitionWithView:splashImage 
     duration:1.5 
     options: UIViewAnimationOptionTransitionCurlUp 
     animations^{ 
      splashImage.frame = CGRectMake(-320, 0, 10, 10); 
     } 
     completion:^(BOOL finished){ 
      [splashImage removeFromSuperview]; 
      //animCompleteHandlerCode.. 
     } 
]; 

沒有測試過,也許一些語法錯誤,但不妨一試!

或者,也許這是更好的:

[UIView animateWithDuration:1.5 
     delay:delay 
     options: UIViewAnimationOptionTransitionCurlUp 
     animations^{ 
      splashImage.frame = CGRectMake(-320, 0, 10, 10); 
     } 
     completion:^(BOOL finished){ 
      [splashImage removeFromSuperview]; 
      //animCompleteHandlerCode.. 
     } 
]; 
+0

我沒有嘗試過這個,但是我很好奇通過你的代碼! ^做什麼?這是嵌入函數的一種方式嗎? – 2010-09-09 11:12:55

+1

這些是iOS 4.0新增的塊。 我鼓勵你閱讀塊。 iOS的很棒的補充。看看這個:http://developer.apple.com/library/ios/#featuredarticles/Short_Practical_Guide_Blocks/index.html 如果我正確理解你的代碼你想要做的是捲曲頁面,同時移動和規模呢? – LarsJK 2010-09-09 12:19:37

+0

移動和縮放並不重要,我只是想引發轉換。正在使用該轉換來測試它正在工作。我只需要將飛濺的圖像卷頁分離。爲了觸發這個過渡,我需要爲視圖做些事情。它會與'隱藏'工作嗎?無論如何,我現在正在進行一些測試。感謝您的反饋意見。 – 2010-09-12 14:08:16

1

@Larsaronen:感謝您的例子,它正是我需要的!我只是想要一個簡單的頁面捲曲而圖像首先顯示出來,所以我用了1.0而不是0α,並設置完成回調到零:

// set a page curl animation for the specified UIImageView control 
- (void) setAnimationPageCurl:(UIImageView *)imageView { 

    [UIView transitionWithView:imageView 
         duration:1.5 
         options:UIViewAnimationOptionTransitionCurlDown 
        animations:^ { imageView.alpha = 1.0; } 
        completion:nil]; 
}