iOS之功能细节iOS开发经验iOS进阶之路

轻松处理界面跳转

2017-09-01  本文已影响629人  gitKong

一、前言


二、应用内跳转

应用类跳转如果细分的话,可以分为跳转到苹果商店和其他App

(3)关键代码如下:(逻辑都比较简单,不详细说明)

- (void)openAppWithUrlScheme:(NSString *)urlScheme params:(NSDictionary<NSString *, id> *)params complete:(void(^)(BOOL success))complete {
  if (!urlScheme.isNotBlank) return;
  NSURL *url = [self urlWithScheme:urlScheme params:params];
  if (!url) return;
  if ([APPLICATION canOpenURL:url]) {
      if ([[[UIDevice currentDevice] systemVersion] compare:@"10.0" options:NSNumericSearch] == NSOrderedAscending) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
          BOOL success = [APPLICATION openURL:url];
#pragma clang diagnostic pop
          if (complete) {
              complete(success);
          }
      }
      else {
          [APPLICATION openURL:url options:@{} completionHandler:^(BOOL success) {
              if (complete) {
                  complete(success);
              }
          }];
      }
  }
  else {
      if (complete) {
          complete(NO);
      }
  }
}

三、Push

Push

三、Modal

Present

抛开需求谈功能都是不切实际,如上图,需求很简单,就是要 present两层后,指定dismiss回到首层控制器,那很简单,dismiss两次就好了。但这样的效果会很难受,实际上,我们只需要获取到指定回到控制器的presentedViewController,然后调用一下 dismiss 就好,那么如何实现呢?


四、Embed

Embed

为了提高用户体验,自定义转场动画是很常见的手段,这里并不是自定义modal,这个是我自己理解的一种转场方式,其实就是嵌套控制器,并且提供多种转场动画。实现起来很简单,代码也比较简单,大家自行查看源码。

- (void)embedViewController:(UIViewController *)vc inParentViewController:(UIViewController *)parentVC animateType:(FLFacadeAnimateType)animateType duration:(NSTimeInterval)duration completion:(void (^)())completion {
    if (vc.parentViewController == parentVC || [self isEmbedViewController:vc isExitAt:parentVC needJudgePrecision:NO]) {
        return;
    }
    
    [parentVC addChildViewController:vc];
    
    [vc willMoveToParentViewController:parentVC];
    
    [self embedView:vc.view atParentView:parentVC.view animateType:animateType];
    
    if (animateType == FLFacadeAnimateTypeNone) {
        [vc didMoveToParentViewController:parentVC];
    }
    else if([self isFadeAnimate:animateType]) {
        [self fadeAnimateWithView:vc.view atParentView:parentVC.view animateType:animateType duration:duration isEmbedAnimated:YES completion:^{
            [vc didMoveToParentViewController:parentVC];
        }];
    }
    else {
        [self transitionWithView:parentVC.view animateType:animateType duration:duration isEmbedAnimated:YES completion:^{
            [vc didMoveToParentViewController:parentVC];
        }];
    }
    if (completion) {
        completion();
    }
}

五、总结

上一篇下一篇

猜你喜欢

热点阅读