代码之家  ›  专栏  ›  技术社区  ›  Lee Probert

iPhone页面卷曲过渡动画

  •  5
  • Lee Probert  · 技术社区  · 14 年前

    我试图用一个 UIImageView

    [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

    更新:

    已经修改了代码,所以它使用了Lars非常简洁的方式来触发一个动画,包括动画和回调。。。

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

    我不确定这是否与语法有关,或者 SplashImage 班级 UIWindow UIView

    2 回复  |  直到 12 年前
        1
  •  8
  •   LarsJK    14 年前

    尝试以下操作:

    [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..
            }
    ];
    
        2
  •  1
  •   Alan    13 年前

    @拉萨罗宁:谢谢你的例子,这正是我需要的!我只想在第一次显示图像时进行简单的页面卷曲,所以我使用了alpha值1.0而不是0,并将完成回调设置为nil:

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