ios 视图切换动画效果

ios view与view间切换的动画效果这篇文章中简单介绍了一种动画效果,下面我详细介绍一下ios中页面间跳转系统自带的动画效果。

动画效果可以参考:http://www.iphonedevwiki.net/index.php?title=UIViewAnimationState

下面先介绍第一组动画效果:


实现的代码是:


//view1中的动画 
- (IBAction)doUIViewAnimation:(id)sender{ 

    [UIView beginAnimations:@"animationID" context:nil]; 
    [UIView setAnimationDuration:10.5f]; 
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
    [UIView setAnimationRepeatAutoreverses:NO]; 

    UIButton *theButton = (UIButton *)sender; 

    switch (theButton.tag) { 
        case 0: 
            [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];//oglFlip, fromLeft 
            break; 

        case 1: 
            [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];//oglFlip, fromRight      
            break; 

        case 2: 
            [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES]; 
            break; 

        case 3: 

            [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES]; 
            break; 

        default: 
            break; 
    } 

    [self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0]; 

    [UIView commitAnimations]; 
}



主要是从不同的角度产生动画。

第二组动画效果:

实现的代码:

- (IBAction)doPublicCATransition:(id)sender{ 

    CATransition *animation = [CATransition animation]; 
    //animation.delegate = self; 
    animation.duration = 10.5f; 
    animation.timingFunction = UIViewAnimationCurveEaseInOut; 
    animation.fillMode = kCAFillModeForwards; 
    //animation.removedOnCompletion = NO; 

    UIButton *theButton = (UIButton *)sender; 

    /* 

     kCATransitionFade; 

     kCATransitionMoveIn; 

     kCATransitionPush; 

     kCATransitionReveal; 

     */ 

    /* 

     kCATransitionFromRight; 

     kCATransitionFromLeft; 

     kCATransitionFromTop; 

     kCATransitionFromBottom; 

     */ 

    switch (theButton.tag) { 

        case 0: 
            animation.type = kCATransitionPush; 
            animation.subtype = kCATransitionFromTop; 
            break; 

        case 1: 
            animation.type = kCATransitionMoveIn; 
            animation.subtype = kCATransitionFromTop; 
            break; 

        case 2: 
            animation.type = kCATransitionReveal; 
            animation.subtype = kCATransitionFromTop; 
            break; 

        case 3: 
            animation.type = kCATransitionFade; 
            animation.subtype = kCATransitionFromTop; 
            break; 

        default: 
            break; 
    } 

    [self.view.layer addAnimation:animation forKey:@"animation"]; 
}

 


下面看一下第三种效果:

代码实现:

- (IBAction)doPrivateCATransition:(id)sender{ 

    //
http://www.iphonedevwiki.net/index.php?title=UIViewAnimationState
    /* 

    Don’t be surprised if Apple rejects your app for including those effects, 
    and especially don’t be surprised if your app starts behaving strangely after an OS update. 
    */ 

    CATransition *animation = [CATransition animation]; 
    animation.delegate = self; 
    animation.duration = 10.5f * slider.value; 
    animation.timingFunction = UIViewAnimationCurveEaseInOut; 
    animation.fillMode = kCAFillModeForwards; 
    animation.endProgress = slider.value; 
    animation.removedOnCompletion = NO; 

    UIButton *theButton = (UIButton *)sender; 

    switch (theButton.tag) { 

        case 0: 
            animation.type = @"cube";//— 
            break; 

        case 1: 
            animation.type = @"suckEffect";//103 
            break; 

        case 2: 
            animation.type = @"oglFlip";//When subType is "fromLeft" or "fromRight", it’s the official one. 
            break; 

        case 3: 
            animation.type = @"rippleEffect";//110 
            break; 

        case 4: 
            animation.type = @"pageCurl";//101 
            break; 

        case 5: 
            animation.type = @"pageUnCurl";//102 
            break; 

        case 6:
            animation.type = @"cameraIrisHollowOpen ";//107 
            break; 

        case 7: 
            animation.type = @"cameraIrisHollowClose ";//106 
            break; 

        default: 
            break; 

    } 

    [self.view.layer addAnimation:animation forKey:@"animation"]; 
    self.lastAnimation = animation; 

    if(slider.value == 1) 
        [self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0];//Just remove, not release or dealloc 
    else{ 
        for (int i = 0; i < [self.view.subviews count]; i++) { 
            [[self.view.subviews objectAtIndex:i] setUserInteractionEnabled:NO]; 
        } 

        isHalfAnimation = YES; 
    } 
}


以上是ios中常用的动画效果,还有一些是利用2d自己写的动画效果,关于自定义动画以后在研究。

源代码: http://easymorse-iphone.googlecode.com/svn/trunk/UIViewDemo/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值