当前位置: 首页 > wzjs >正文

平台网站模板 优帮云福州市工程造价信息网

平台网站模板 优帮云,福州市工程造价信息网,有没有网站建设的兼职,网站页面如何设计图push 🆚 present 前言present和dismiss特点代码演示 push和pop特点代码演示 前言 在 iOS 开发中,push 和 present 是两种不同的视图控制器切换方式,它们有着显著的区别。 present和dismiss 特点 在当前控制器上方新建视图层级需要手动调用…

push 🆚 present

  • 前言
  • present和dismiss
    • 特点
    • 代码演示
  • push和pop
    • 特点
    • 代码演示

前言

在 iOS 开发中,pushpresent 是两种不同的视图控制器切换方式,它们有着显著的区别。

present和dismiss

特点

  • 在当前控制器上方新建视图层级
  • 需要手动调用dismiss
ViewController* vc = [[ViewController alloc] init];
[self presentViewController:vc2 animated:YES completion:nil];

对应的dismiss方法:(用于关闭或取消当前显示的视图、对话框等)

[self dismissViewControllerAnimated:YES completion:nil];
  • 默认从下向上滑入
  • 只保留当前presented的控制器
  • 可配置为全屏覆盖

代码演示

新建View02类作为视图控制器二

dimiss方法在View02文件中实现

#import "View02.h"@interface View02 ()@end@implementation View02- (void)viewDidLoad {[super viewDidLoad];self.view.backgroundColor = [UIColor cyanColor];
}-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {[self dismissViewControllerAnimated:YES completion:nil];
}

作为视图控制器一

present方法在ViewController文件中实现

#import "ViewController.h"
#import "View02.h"
@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];[self creatUIRectButton];
}
- (void)creatUIRectButton {UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];btn1.frame = CGRectMake(10, 400, 120, 80);[btn1 setTitle:@"test button" forState:UIControlStateNormal];[btn1 setTitle:@"按下时候" forState:UIControlStateHighlighted];[btn1 addTarget:self action:@selector(press) forControlEvents:UIControlEventTouchUpInside];[btn1 setTintColor:[UIColor whiteColor]];btn1.backgroundColor = [UIColor grayColor];[self.view addSubview: btn1];
}
- (void) press {View02* vc = [[View02 alloc] init];[self presentViewController:vc animated:YES completion: nil];
}@end

运行效果:

在这里插入图片描述

push和pop

特点

  • 用于导航控制器堆栈中的视图控制器的界面切换。压入导航栈,成为栈顶控制器
ViewController* vc = [[ViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];

对应的消失视图方法为:

[self.navigationController popViewControllerAnimated:YES];
  • 系统自动生成返回按钮
  • 新视图从右向左滑入
  • 保留所有pushed的控制器
  • 不能全屏覆盖

代码演示

创建一个导航控制器:

//SceneDelegate.m
#import "SceneDelegate.h"
#import "VCRoot.h"
@interface SceneDelegate ()@end@implementation SceneDelegate- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {self.window.frame = [UIScreen mainScreen].bounds;UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[[VCRoot alloc] init]];self.window.rootViewController = nav;[self.window makeKeyAndVisible];
}

第一个视图控制器:

#import "VCRoot.h"
#import "VCSecond.h"
@interface VCRoot ()@end@implementation VCRoot- (void)viewDidLoad {[super viewDidLoad];self.navigationController.navigationBar.translucent = YES;self.title = @"title";self.navigationItem.title = @"根视图";self.view.backgroundColor = [UIColor blueColor];self.navigationController.navigationBar.barStyle = UIBarStyleDefault;UIBarButtonItem *next = [[UIBarButtonItem alloc] initWithTitle:@"下一级" style:UIBarButtonItemStylePlain target:self action:@selector(pressRight)];self.navigationItem.rightBarButtonItem = next;
}
-(void)pressRight {VCSecond *vc2 = [[VCSecond alloc] init];[self.navigationController pushViewController:vc2 animated:YES];
}

第二个视图控制器:

#import "VCSecond.h"
#import "VCthird.h"
@interface VCSecond ()@end@implementation VCSecond- (void)viewDidLoad {[super viewDidLoad];self.view.backgroundColor = [UIColor yellowColor];UIBarButtonItem *btnNext = [[UIBarButtonItem alloc] initWithTitle:@"next" style:UIBarButtonItemStylePlain target:self action:@selector(press)];self.navigationItem.rightBarButtonItem = btnNext;
}
-(void)press {VCthird *vc3 = [[VCthird alloc] init];[self.navigationController pushViewController:vc3 animated:YES];
}

第三个视图控制器:

#import "VCthird.h"@interface VCthird ()@end@implementation VCthird- (void)viewDidLoad {[super viewDidLoad];self.view.backgroundColor = [UIColor cyanColor];UIBarButtonItem *btnLeft = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(pressBack)];self.navigationItem.rightBarButtonItem = btnLeft;
}
-(void)pressBack {[self.navigationController popToRootViewControllerAnimated:YES];
}

运行效果:

在这里插入图片描述

http://www.dtcms.com/wzjs/841384.html

相关文章:

  • 建设部网站举报门户网站建设制作
  • 外贸手工做兼职的网站辣条网站建设书
  • 辽宁旅游网站开发网站群建设需求
  • 做it公司网站标志与设计
  • 点击进入官方网站重庆忠县网站建设
  • node做网站优势防止网站被采集
  • 浏阳网站制作公司注册网站免费
  • 淄博网站制作升级优化中核二二建设有限公司
  • 网页制作网站的大作业宜昌seo优化
  • 在windows2003上做网站厦门网站建设a
  • 音乐网站开发背景百度关键词搜索量排名
  • 网站建设做微营销目前比较火的外贸产品
  • 中山专业网站制作产品设计考研学校
  • 住房与城乡建设部网站打不开企业网站制作费做分录
  • 如何做电商带货网站建设优化河南
  • 做旅游网约车的网站做服装网站要那些照片
  • 中文域名网站有哪些桂林两江四湖门票多少钱
  • 做班级玩网站做哪些方面外包公司有哪些
  • 厦门网站个人制作网站制作的基本步骤
  • 北京王府井集团股份有限公司郑州网站优化外包顾问
  • 网站做图分辨率是多少求做图的网站
  • 哈尔滨网站建设1元钱网站团购活动页面怎么做
  • 西安 网站建设 培训学校防做电脑租赁网站
  • 义乌 外贸网站 开发如何查看网站外链
  • 本地的wordpress地址关键词优化推广排名软件
  • 中国手机网站大全南昌建筑行业网站开发
  • 如何创建属于自己的网站高清视频网络服务器免费
  • 适用于建设微型网站成都官网搭建公司
  • 张家港专业做网站网站建设制作专业
  • 域名备案网站服务内容这两天发生的重大新闻