基础动画的使用

// 基础动画

- (void)moveView:(UIButton *)btn

{

    NSLog(@"%s",__FUNCTION__);

    // 开始 名字随便取

    [UIView beginAnimations:@"aaa" context:nil];

    // 动画类型

    [UIView setAnimationCurve:UIViewAnimationCurveLinear];

    // 时长

    [UIView setAnimationDuration:1.0];

    // 代理

    [UIView setAnimationDelegate:self];

    // default = NULL. -animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context

    // animationID对应上面的@"aaa"

    //[UIView setAnimationDidStopSelector:@selector(stopAnim)];

    /* 动画的处理写在这里 */

    // 改变上下视图的动画1、动画类型 2、两个视图的父视图 3yes

    /*

     UIViewAnimationTransitionNone,

     UIViewAnimationTransitionFlipFromLeft,

     UIViewAnimationTransitionFlipFromRight,

     UIViewAnimationTransitionCurlUp, // 翻页效果

     UIViewAnimationTransitionCurlDown, //

     */

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

    // 在父视图调换两个视图层级

    // NSInteger index = [self.view.subviews indexOfObject:animView];

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

    // 提交动画

    [UIView commitAnimations];

    

    /* block实现动画 */

    [UIView animateWithDuration:0.5 animations:^{

        // 动画内容

    } completion:^(BOOL finished) {

        // 动画结束处理

    }];

}

// 缩放动画

- (void)scaleAnim

{

    // 初始值

    CGAffineTransform Transform = animView.transform;

    // 缩放比例

    animView.transform = CGAffineTransformScale(Transform, 1, 1);

    [UIView animateWithDuration:0.5 animations:^{

        // 缩放到0.01,改值不能为零

        animView.transform = CGAffineTransformScale(animView.transform, 0.01, 0.01);

    } completion:^(BOOL finished) {

        // 恢复为原始状态

        animView.transform = CGAffineTransformIdentity;

    }];

}

// 核心动画

- (void)coreAnim

{

    CATransition *anim = [CATransition animation];

    anim.duration = 0.6;

    // 加速、减速等 `linear', `easeIn', `easeOut' and`easeInEaseOut' and `default'

    anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];

    // 淡入、push

    anim.type = kCATransitionReveal;

    // type的子类型/ 上下左右等

    anim.subtype = kCATransitionFromLeft;

    // 名字随便

    [self.view.layer addAnimation:anim forKey:@"abc"];

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

}

// 改变导航控制器push动画

- (void)customNavAnim

{

    CATransition *transition = [CATransition animation];

    transition.duration  = 0.7;

    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

    transition.type = kCATransitionPush;

    transition.subtype = kCATransitionFromLeft;

    // 动画加在layer

    [self.navigationController.view.layer addAnimation:transition forKey:@"ccc"];

    // 推出下一视图即可

    UIViewController *vc = [[UIViewController alloc] init];

    // 不显示系统动画 NO

    [self.navigationController pushViewController:vc animated:NO];

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值