热门标签 | HotTags
当前位置:  开发笔记 > 运维 > 正文

iOS中模态Model视图跳转和Push视图跳转的需求实现方法

这篇文章主要介绍了iOS中模态Model视图跳转和Push视图跳转的需求实现,非常不错,具有参考借鉴价值,需要的朋友可以参考下

本文给大家分享下模态Model视图跳转和Push视图跳转的需求实现。

  开前自打小广告:一键合成APP引导页,包含不同状态下的引导页操作方式,同时支持动态图片引导页和静态图片引导页以及视频引导页;GitHub地址: https://github.com/dingding3w/DHGuidePageHUD (多多Star,多多支持😊);

  (一)连续两次模态Model视图之后,然后返回首页(A -> B -> C -> A)

  ①效果图展示:

  ②核心代码展示:

/** 在C页面的DisMiss方法里面添加一下代码(iOS6.0+) */
  if ([self respondsToSelector:@selector(presentingViewController)]){
    [self.presentingViewController.presentingViewController dismissViewControllerAnimated:YES completion:nil];
  }
  else {
    [self.parentViewController.parentViewController dismissViewControllerAnimated:YES completion:nil];
  }

  (二)在模态Model推出的视图中Push下一个带导航栏的视图,然后返回首页(A -> B ->C -> A)

  ①效果图展示:

  ②核心代码展示:

/** 这里用到的核心处理办法是 */
/** 1.在A控制器模态Model推出B控制器的时候先给B控制器包装一个导航控制器 */
UINavigationController *ANavigatiOnController= [[UINavigationController alloc] initWithRootViewController:[[BViewController alloc] init]];
[self presentViewController:ANavigationController animated:YES completion:nil];
/** 2.在B控制器遵守UINavigationControllerDelegate实现代理协议,隐藏当前控制器的导航栏 */
#pragma mark - UINavigationControllerDelegate
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
  // 判断要显示的控制器是否是自身控制器
  BOOL isShowMyCOntroller= [viewController isKindOfClass:[self class]];
  [self.navigationController setNavigationBarHidden:isShowMyController animated:YES];
}
#pragma mark - Push出C控制器
[self.navigationController pushViewController:[[CViewController alloc] init] animated:YES];
/** 3.在C控制器里面可直接在返回按钮方法里DisMiss */
[self.navigationController dismissViewControllerAnimated:YES completion:nil];

以上所述是小编给大家介绍的iOS中模态Model视图跳转和Push视图跳转的需求实现方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!


推荐阅读
author-avatar
天之蓝
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有