IOS开发之UI进阶(UITabBarController、代码跳转)

UITabBarController

开始运行,只加载第一个页面,使用哪个再加载哪个,不销毁

  • 添加子控制器
UIViewController *v1 = [UIViewController new];
[tabBarController addChildViewController:v1];

UITabBar

UITabBarController下方的导航栏

UITabBarButton

  • UITabBarButton里由什么内容,由对应子控制器的 tabBarItem属性决定
  • tabBarItem有以下属性影响UITabBarButton的内容
//标题文字
@property(nonatomic,copy) NSString *title;
//图标
@property(nonatomic,retain) UIImage *image;
//选中时的图标
@property(nonatomic,retain) UIImage *selectedImage;
//提醒数字/文字
@property(nonatomic,copy) NSString *badgeValue;
v1.tabBarItem.title = @"联系人";
v1.tabBarItem.image = [UIImage imageNamed:@"pic"];

App主流UI框架结构

在这里插入图片描述

跳转方式

  • Push的默认效果:新控制器从右往左,直到盖住之前的控制器,一般是业务逻辑有关系使用
  • Modal的默认效果:新控制器从屏幕下往上钻,直到盖住之前的控制器,一般是业务逻辑没有关系使用
//以Modal的形式展示控制器
-(void)persentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion

//关闭当初Model出来的控制器
-(void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion

代码跳转

  • Modal的形式展示控制器
    该方法是谁负责显示,谁负责关闭,A打开B,B运行dismissViewControllerAnimated时,其实是向A发送消息,由A负责关闭
    UIViewController *VC = [UIViewController new];
    VC.view.backgroundColor = [UIColor redColor];
    //设置跳转方式,默认Modal
    VC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    //completion是回调
    [self presentViewController:VC animated:YES completion:^{
        NSLog(@"跳转成功!");
    }];
	//跳转回去
	[self dismissViewControllerAnimated:YES completion:nil];
	跳转的展现形式
	typedef NS_ENUM(NSInteger, UIModalTransitionStyle) {
    	UIModalTransitionStyleCoverVertical = 0,
    	UIModalTransitionStyleFlipHorizontal API_UNAVAILABLE(tvos),
    	UIModalTransitionStyleCrossDissolve,
    	UIModalTransitionStylePartialCurl API_AVAILABLE(ios(3.2)) API_UNAVAILABLE(tvos),
	};
  • iOS 13.0以后presentViewController 不全屏的问题
	IOS13以后默认为:UIModalPresentationAutomatic(不全屏+缩放+透明背景),可以改为原来的值,就可以全屏展示了
	self.modalPresentationStyle = UIModalPresentationOverFullScreen;//全屏+透明背景+不缩放
	//UIModalPresentationFullScreen 全屏+白色背景

navigationController跳转

	//如果有navigationController,也可以执行该方法
	[self.navigationController pushViewController:VC animated:YES];
	//回去
	[self.navigationController popViewControllerAnimated:YES];

	//跳转指定的页面
	NSArray *vcArr = self.navigationController.viewControllers;
    [self.navigationController popToViewController:vcArr[0] animated:YES];//跳转最外面
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值