2010-09-08 122 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]; 
}