IOS图像5之UIView动画、自定义转场动画、delegate

UIView淡入淡出动画、3D旋转动画

    淡入淡出动画

    UIView *view01 = [[UIView alloc]initWithFrame:CGRectMake(20, 20, 100, 50)];

    view01.backgroundColor = [UIColor redColor];

    [self.view addSubview:view01];

    view01.alpha = 1.0;

    [UIView beginAnimations:nil context:nil];

    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

    [UIView setAnimationDuration:3.0];

    [UIView setAnimationRepeatCount:3];

    [UIView setAnimationDelegate:self];

    view01.alpha = 0.0;

    [UIView commitAnimations];

3D旋转Block动画:

    UIView *view01 = [[UIView alloc]initWithFrame:CGRectMake(20, 20, 100, 50)];

    [UIView animateWithDuration:2 animations:^{

        view01.backgroundColor = [UIColor cyanColor];

        view01.alpha = 1.0;

        [self.view addSubview:view01];

        [UIView setAnimationDuration:2.0];

        [UIView setAnimationRepeatCount:1.0];

        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

        view01.transform = CGAffineTransformMakeRotation(3.14);

    } completion:^(BOOL finish){

        if (finish) {

            NSLog(@"animationstop");

        }

这里设置动画结束之后还有一些代理方法,例如stop动画结束的完成回调方法,start动画开始回调方法等等。

自定义转场动画:

从IOS7之后可以定义自定义转场动画:


-(void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext{

    UIViewController * viewfrom = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];

    UIViewController * viewto = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];

    UIView *mtransitionContext = [transitionContext containerView];


        [mtransitionContext addSubview:viewfrom.view];

        [mtransitionContext addSubview:viewto.view];

        viewto.view.frame = CGRectMake(100, 0, 320, 568);

        [UIView animateWithDuration:5.0 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^(){

            viewto.view.frame = CGRectMake(0, 0, 320, 568);

        } completion:^(BOOL finished){

            [transitionContext completeTransition:YES];

        }];

   

}

剩下的我们只需要实现navigation的代理协议就可以了:

-(id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC{

    id anim = nil;

    anim = mslid;

    return  anim;

}



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值