指纹解锁以及自定义转场动画

这两天工作不忙,就去研究了下指纹解锁以及转场动画,其实这里面的单单一个动画就可以说半天了,但是今天不去说动画。这个以后有时间在讲讲。。

指纹解锁,很简单,官方文档上说的很清楚,其实我们要做的几乎没有。。

1、导入 #import <LocalAuthentication/LocalAuthentication.h> 这个框架

2、导入下面那段代码,指纹解锁就完成了, so easy!!!!然后再实现自己大逻辑就可以了。。

 LAContext *myContext = [[LAContext alloc]init];
    myContext.localizedFallbackTitle = @"忘记密码";
    
    NSError *error = nil;
    NSString *myLocalizedReasonString = @"请输入指纹";
//判断是否支持指纹解锁功能 if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) { //支持指纹解锁 [myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:myLocalizedReasonString reply:^(BOOL success, NSError *error) { if (success) { //成功 [self showAlerView:@"验证成功"]; } else { //失败 [self showAlerView:@"验证失败"]; NSLog(@"did not authenticate successfully"); } }]; } else { //不支持指纹解锁 NSLog(@"Could not evaluate policy"); [self showAlerView:@""]; }

  

 

指纹解锁完成了,接下来是自定义转场动画

1、在viewcontrol中实现UINavigationControllerDelegate的 下面这个方法

- (nullable id <UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController
                                            animationControllerForOperation:(UINavigationControllerOperation)operation
                                                         fromViewController:(UIViewController *)fromVC
                                                           toViewController:(UIViewController *)toVC  NS_AVAILABLE_IOS(7_0)
{
    
    if (operation == UINavigationControllerOperationPush) {
        
        return self.animator;
    }
    return nil;

}

2、创建一个类继承NSObject,遵循 UIViewControllerAnimatedTransitioning

/**
 *  动画的时间按
 */
- (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)transitionContext
{
    return 1;
}

/**
 *  执行的动画
 *
 */
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
    UIViewController* toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    UIViewController* fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    [[transitionContext containerView] addSubview:toViewController.view];
    toViewController.view.alpha = 0;
    
    [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
      
        CATransition *tion = [CATransition animation];
        tion.type = @"oglFlip";
        tion.subtype = kCATransitionFromTop;
        tion.duration = 1;
        [fromViewController.view.layer addAnimation:tion forKey:nil];

        
        // fromViewController.view.transform = CGAffineTransformMakeRotation(0.5);//CGAffineTransformMakeScale(0.1, 0.1);
        toViewController.view.alpha = 1;
    } completion:^(BOOL finished) {
        fromViewController.view.transform = CGAffineTransformIdentity;
        [transitionContext completeTransition:![transitionContext transitionWasCancelled]];
    }];
}

  

 

 

 

 

你可能感兴趣的:(指纹解锁以及自定义转场动画)