UINavigationController讲解(一)

2024-05-05 01:18

本文主要是介绍UINavigationController讲解(一),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

UINavigationController讲解(一)

UINavigationController简单介绍

  1. 初始化

    //通过一个自定义的导航栏和工具栏创建导航控制器
    - (instancetype)initWithNavigationBarClass:(nullable Class)navigationBarClass toolbarClass:(nullable Class)toolbarClass NS_AVAILABLE_IOS(5_0);
    //使用系统默认的导航栏和工具栏,通过一个根视图创建导航控制器
    - (instancetype)initWithRootViewController:(UIViewController *)rootViewController;
    
  2. 导航栏常用方法

    //通过压栈方式压入新的控制器(切换界面)
    - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated; // Uses a horizontal slide transition. Has no effect if the view controller is already in the stack.
    //从栈中弹出顶部控制器(返回)
    - (UIViewController *)popViewControllerAnimated:(BOOL)animated; // Returns the popped controller.
    //从栈中弹出到某个控制器 返回所有pop的controller
    - (NSArray<__kindof UIViewController *> *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated; // Pops view controllers until the one specified is on top. Returns the popped controllers.
    //直接pop到根视图控制器,弹出所有控制器
    - (NSArray<__kindof UIViewController *> *)popToRootViewControllerAnimated:(BOOL)animated;
  3. 常用属性

    //栈顶的控制器
    @property(nullable, nonatomic,readonly,strong) UIViewController *topViewController; 
    //显示的controller(包括present出的控制器)
    @property(nullable, nonatomic,readonly,strong) UIViewController *visibleViewController;
    //栈中所有的控制器
    @property(nonatomic,copy) NSArray<__kindof UIViewController *> *viewControllers;
    //设置隐藏导航栏
    @property(nonatomic,getter=isNavigationBarHidden) BOOL navigationBarHidden;
    - (void)setNavigationBarHidden:(BOOL)hidden animated:(BOOL)animated;
    //导航栏对象,只读属性
    @property(nonatomic,readonly) UINavigationBar *navigationBar;
    //隐藏状态栏
    @property(nonatomic,getter=isToolbarHidden) BOOL toolbarHidden NS_AVAILABLE_IOS(3_0);
    - (void)setToolbarHidden:(BOOL)hidden animated:(BOOL)animated;
    //状态栏对象
    @property(null_resettable,nonatomic,readonly) UIToolbar *toolbar;
    //导航中的返回手势对象
    //iOS7之后,在导航中右划会进行pop操作,设置这个的enable可以控制设置手势是否失效
    @property(nullable, nonatomic, readonly) UIGestureRecognizer *interactivePopGestureRecognizer;
    //这个方法是为了iOS方法的命名统一,在导航中,其作用和push一样
    - (void)showViewController:(UIViewController *)vc sender:(nullable id)sender;
    //弹出键盘的时候隐藏导航栏
    @property (nonatomic, readwrite, assign) BOOL hidesBarsWhenKeyboardAppears;
    //屏幕滑动的时候隐藏导航栏,常用于tableView,上滑隐藏导航栏,下滑显示,带动画效果
    @property (nonatomic, readwrite, assign) BOOL hidesBarsOnSwipe;
    //滑动隐藏导航栏的手势
    @property (nonatomic, readonly, strong) UIPanGestureRecognizer *barHideOnSwipeGestureRecognizer;
    //横屏的时候隐藏导航栏
    @property (nonatomic, readwrite, assign) BOOL hidesBarsWhenVerticallyCompact;
    //敲击屏幕可以隐藏与显示导航栏
    @property (nonatomic, readwrite, assign) BOOL hidesBarsOnTap;
    //敲击屏幕的手势
    @property (nonatomic, readonly, assign) UITapGestureRecognizer *barHideOnTapGestureRecognizer;
  4. UINavigationDelegate

    //视图将要展示时调用的方法
    - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated;
    //视图已经展示时调用的方法
    - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated;
    //设置方法设置导航控制器支持的设备方向
    - (UIInterfaceOrientationMask)navigationControllerSupportedInterfaceOrientations:(UINavigationController *)navigationController NS_AVAILABLE_IOS(7_0);
    //这个方法设置导航控制器的首选设备方向
    - (UIInterfaceOrientation)navigationControllerPreferredInterfaceOrientationForPresentation:(UINavigationController *)navigationController NS_AVAILABLE_IOS(7_0);
    //下面两个方法可以对导航的转场动画进行设置
    - (nullable id <UIViewControllerInteractiveTransitioning>)navigationController:(UINavigationController *)navigationController interactionControllerForAnimationController:(id <UIViewControllerAnimatedTransitioning>) animationController;
    - (nullable id <UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC ;
    

这篇关于UINavigationController讲解(一)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/960501

相关文章

嵌入式数据库SQLite 3配置使用讲解

《嵌入式数据库SQLite3配置使用讲解》本文强调嵌入式项目中SQLite3数据库的重要性,因其零配置、轻量级、跨平台及事务处理特性,可保障数据溯源与责任明确,详细讲解安装配置、基础语法及SQLit... 目录0、惨痛教训1、SQLite3环境配置(1)、下载安装SQLite库(2)、解压下载的文件(3)、

Java进程CPU使用率过高排查步骤详细讲解

《Java进程CPU使用率过高排查步骤详细讲解》:本文主要介绍Java进程CPU使用率过高排查的相关资料,针对Java进程CPU使用率高的问题,我们可以遵循以下步骤进行排查和优化,文中通过代码介绍... 目录前言一、初步定位问题1.1 确认进程状态1.2 确定Java进程ID1.3 快速生成线程堆栈二、分析

javascript fetch 用法讲解

《javascriptfetch用法讲解》fetch是一个现代化的JavaScriptAPI,用于发送网络请求并获取资源,它是浏览器提供的全局方法,可以替代传统的XMLHttpRequest,这篇... 目录1. 基本语法1.1 语法1.2 示例:简单 GET 请求2. Response 对象3. 配置请求

Java Stream.reduce()方法操作实际案例讲解

《JavaStream.reduce()方法操作实际案例讲解》reduce是JavaStreamAPI中的一个核心操作,用于将流中的元素组合起来产生单个结果,:本文主要介绍JavaStream.... 目录一、reduce的基本概念1. 什么是reduce操作2. reduce方法的三种形式二、reduce

CSS引入方式和选择符的讲解和运用小结

《CSS引入方式和选择符的讲解和运用小结》CSS即层叠样式表,是一种用于描述网页文档(如HTML或XML)外观和格式的样式表语言,它主要用于将网页内容的呈现(外观)和结构(内容)分离,从而实现... 目录一、前言二、css 是什么三、CSS 引入方式1、行内样式2、内部样式表3、链入外部样式表四、CSS 选

Python Transformers库(NLP处理库)案例代码讲解

《PythonTransformers库(NLP处理库)案例代码讲解》本文介绍transformers库的全面讲解,包含基础知识、高级用法、案例代码及学习路径,内容经过组织,适合不同阶段的学习者,对... 目录一、基础知识1. Transformers 库简介2. 安装与环境配置3. 快速上手示例二、核心模

C++ vector的常见用法超详细讲解

《C++vector的常见用法超详细讲解》:本文主要介绍C++vector的常见用法,包括C++中vector容器的定义、初始化方法、访问元素、常用函数及其时间复杂度,通过代码介绍的非常详细,... 目录1、vector的定义2、vector常用初始化方法1、使编程用花括号直接赋值2、使用圆括号赋值3、ve

Java调用C++动态库超详细步骤讲解(附源码)

《Java调用C++动态库超详细步骤讲解(附源码)》C语言因其高效和接近硬件的特性,时常会被用在性能要求较高或者需要直接操作硬件的场合,:本文主要介绍Java调用C++动态库的相关资料,文中通过代... 目录一、直接调用C++库第一步:动态库生成(vs2017+qt5.12.10)第二步:Java调用C++

Python基础文件操作方法超详细讲解(详解版)

《Python基础文件操作方法超详细讲解(详解版)》文件就是操作系统为用户或应用程序提供的一个读写硬盘的虚拟单位,文件的核心操作就是读和写,:本文主要介绍Python基础文件操作方法超详细讲解的相... 目录一、文件操作1. 文件打开与关闭1.1 打开文件1.2 关闭文件2. 访问模式及说明二、文件读写1.

C# WinForms存储过程操作数据库的实例讲解

《C#WinForms存储过程操作数据库的实例讲解》:本文主要介绍C#WinForms存储过程操作数据库的实例,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、存储过程基础二、C# 调用流程1. 数据库连接配置2. 执行存储过程(增删改)3. 查询数据三、事务处