Animation

动画效果

typedef enum : NSUInteger {
    //UIViewAnimation
    CurlDown = 1,               //下翻页
    CurlUp,                     //上翻页
    FlipFromLeft,               //左翻转
    FlipFromRight,              //右翻转
    //CATransition
    Fade,                       //淡入淡出
    Push,                       //推挤
    Reveal,                     //揭开
    MoveIn,                     //覆盖
    
    //以下为私有api
    Cube,                       //立方体
    SuckEffect,                 //吮吸
    OglFlip,                    //翻转
    RippleEffect,               //波纹
    PageCurl,                   //翻页
    PageUnCurl,                 //反翻页
    CameraIrisHollowOpen,       //开镜头
    CameraIrisHollowClose,      //关镜头
} AnimationType;

//创建CATransition对象
    CATransition *animation = [CATransition animation];
    
    //设置运动时间
    animation.duration = DURATION;
    
    //设置运动type
    animation.type = type;
    if (subtype != nil) {
        
        //设置子类
        animation.subtype = subtype;
    }
    
    //设置运动速度
    animation.timingFunction = UIViewAnimationOptionCurveEaseInOut;
    
    [view.layer addAnimation:animation forKey:@"animation"];


[UIView animateWithDuration:DURATION animations:^{
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [UIView setAnimationTransition:transition forView:view cache:YES];
}];

原文链接

UIViewControllerAnimatedTransitioning实现界面跳转动画

一、新建NSObject类实现UIViewControllerAnimatedTransitioning协议

- (NSTimeInterval)transitionDuration:(id)transitionContext{
    return 1.f;
}

- (void)animateTransition:(id)transitionContext{
    UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    //无论是push还是pop即将出现的视图为toVC;
    UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    [[transitionContext containerView] addSubview:toVC.view];
    if (self.navigationOperation == UINavigationControllerOperationPush) {
        toVC.view.transform = CGAffineTransformMakeScale(0, 0);
     //根据需求实现想要的效果,此处为缩放
        [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
            toVC.view.transform = CGAffineTransformMakeScale(1.0, 1.0);
        } completion:^(BOOL finished) {
            [transitionContext completeTransition:YES];
        }];
    }else if (self.navigationOperation == UINavigationControllerOperationPop){
        //没什么效果
        fromVC.view.transform = CGAffineTransformMakeScale(1.0, 1.0);
        [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
            fromVC.view.transform = CGAffineTransformMakeScale(0, 0);
        } completion:^(BOOL finished) {
            [transitionContext completeTransition:YES];
        }];
    }
    
}

二、第一个控制器中实现代理UIViewControllerTransitioningDelegate,通过UINavigationController跳转的还要再实现UINavigationControllerDelegate

#pragma mark -- UIViewControllerTransitioningDelegate
- (id)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source{
    return self.scaleAnimation;
}

#pragma mark -- UINavigationControllerDelegate
- (id)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC{
    if (operation == UINavigationControllerOperationPush) {
        self.scaleAnimation.navigationOperation = UINavigationControllerOperationPush;
        return self.scaleAnimation;
    }else{
        return nil;
    }
}

你可能感兴趣的:(Animation)