
在项目开发过程中,完成iOS项目(项目开发环境)的构建后,我们首先需要考虑项目的总体框架和导航架构设计,然后考虑完成功能模块的开发. 这个基础.
应用程序的导航架构设计应与人们的操作惯性和方便的操作相一致,并且在交互中应更加合理和人性化. 根据项目的功能和位置的不同,不同应用程序的导航设计应使用不同的技术框架. 当前,比较常见的导航框架主要包括三种类型: 标签,列表和矩阵,如下所示.

目前,用于新闻和新闻的移动新闻项目的主流App框架已基本确定. 这种导航设计技术基本上是通过TabBar + NavigationController框架完成的. 您经常使用的微博,今天的标题等都是TabBar + NavigationController之类的框架. TabBar + NavigationController将在TabBar上添加itemBar,每个itemBar是一个独立的模块,并且每个itemBar对应于一个NavigationController. 因为每个itemBar都有一个不同的导航器,所以它应该先具有TabBar,然后才具有NavigationController.

我们的项目也属于信息类别,因此我们的项目框架也使用TabBar + NavigationController构建. 今天ios框架,我们的主要任务是构建TabBar. 如果您使用系统随附的UITabBarController(此处印有官方网站文档),则在使用过程中需要注意以下几点:
每个barItem必须与一个ViewController对应,该ViewController可以是常规ViewController,也可以是与UINavigationController barItem对应的ViewController或UINavigationController. 如果框架是自定义的,请注意不要阻塞底部TabBar barItem的顺序和添加. UITabBarController的顺序保持不变. 当添加的barItems数量<= 5时,它们均匀分布在底部栏上,如上图所示. 当添加的barItems的数量> 5时,将仅显示前四个. 添加一个barItem,然后添加一个[更多],单击[更多]弹出一个列表供选择,并且该列表的右上角有一个[编辑]按钮. 单击后,可以调整barItem的显示顺序,如下图所示,因此TabBar + NavigationController框架下的barItem数最好不超过5,否则用户体验不是很好.



添加与itemBar对应的ViewController的方法有两种: 一种是使用UITabBarController的setViewControllers: 方法进行设置;另一种是使用setViewControllers: 方法. 另一种方法是使用UIViewController的addChildViewController: 方法添加子视图,也可以将其添加到tabBar函数,但是此方法当barItems的数量> 5时,仅显示前五个,而不会显示其余五个当它们出现时会出现,并且没有[more]按钮可供选择.
示例代码如下,自定义的TabBarController继承自UITabBarController,然后重写其viewDidLoad方法以添加子视图和标签:
@implementation XMGTabBarController
- (void)viewDidLoad {
[super viewDidLoad];
//添加4个item bar
UITableViewController *vc0 = [[UITableViewController alloc] init];
vc0.view.backgroundColor = [UIColor redColor];
vc0.tabBarItem.title = @"精华";
vc0.tabBarItem.image = [UIImage imageNamed:@"tabBar_essence_icon"];
vc0.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_essence_click_icon"];
[self addChildViewController:vc0];
UIViewController *vc1 = [[UIViewController alloc] init];
vc1.view.backgroundColor = [UIColor blueColor];
vc1.tabBarItem.title = @"新帖";
vc1.tabBarItem.image = [UIImage imageNamed:@"tabBar_new_icon"];
vc1.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_new_click_icon"];
[self addChildViewController:vc1];
UITableViewController *vc2 = [[UITableViewController alloc] init];
vc2.view.backgroundColor = [UIColor greenColor];
vc2.tabBarItem.title = @"关注";
vc2.tabBarItem.image = [UIImage imageNamed:@"tabBar_friendTrends_icon"];
vc2.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_friendTrends_click_icon"];
[self addChildViewController:vc2];
UIViewController *vc3 = [[UIViewController alloc] init];
vc3.view.backgroundColor = [UIColor grayColor];
vc3.tabBarItem.title = @"我";
vc3.tabBarItem.image = [UIImage imageNamed:@"tabBar_me_icon"];
vc3.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_me_click_icon"];
[self addChildViewController:vc3];
//下面的方法也是可以的,推荐使用下面的方法
// [self addChildViewController:@[vc0,vc1,vc2,vc3]];
}
在开发过程中,我们最好不要重复编写相同的代码. 因此,在开发过程中,我们需要重构和简化代码. 主要原理是保留一种方法来实现功能,然后尝试不要编写重复的代码,简化逻辑. 代码中有很多重复的代码,这些代码在我们前面添加了tabBar项,因此我们需要对其进行重构,提取重复的代码,并将不同的内容设置为自定义设置的参数. 逻辑如下:
@implementation XMGTabBarController
- (void)viewDidLoad {
[super viewDidLoad];
/**** 添加子控制器 ****/
[self setupOneChildViewController:[[UITableViewController alloc] init] title:@"精华" image:@"tabBar_essence_icon" selectedImage:@"tabBar_essence_click_icon"];
[self setupOneChildViewController:[[UITableViewController alloc] init] title:@"新帖" image:@"tabBar_new_icon" selectedImage:@"tabBar_new_click_icon"];
[self setupOneChildViewController:[[UIViewController alloc] init] title:@"关注" image:@"tabBar_friendTrends_icon" selectedImage:@"tabBar_friendTrends_click_icon"];
[self setupOneChildViewController:[[UITableViewController alloc] init] title:@"我" image:@"tabBar_me_icon" selectedImage:@"tabBar_me_click_icon"];
}
/**
* 初始化一个子控制器
*
* @param vc 子控制器
* @param title 标题
* @param image 图标
* @param selectedImage 选中的图标
*/
- (void)setupOneChildViewController:(UIViewController *)vc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage
{
vc.view.backgroundColor = [UIColor redColor];
vc.tabBarItem.title = title;
vc.tabBarItem.image = [UIImage imageNamed:image];
vc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];
[self addChildViewController:vc];
}
@end
在iOS开发过程中,系统自身的空间有时会在显示时自动渲染一些图片,例如,选中TabBarItem时的图片,以及设置UIButtonTypeSystem样式时的按钮的图片. 此时,系统将自动呈现蓝色.
vc.tabBarItem.selectedImage = image; UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem]; [btn setImage:image forState:UIControlStateNormal];

3.1图像渲染问题
有时候在开发过程中不需要这种渲染,我们只是希望已开发的应用程序根据我们设置的图片进行显示. 这是我们需要禁止渲染图片的设置和操作. 有两种解决方案:
生成不会再次渲染的图片
// 加载图片 UIImage *tempImage = [UIImage imageNamed:@"tabBar_essence_click_icon"]; // 产生一张不会进行自动渲染的图片 UIImage *selectedImage = [tempImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; vc.tabBarItem.selectedImage = selectedImage;
直接在xcassets文件中配置不渲染的图像

3.2设置TabBarItem的文本属性
修改我们团队的上述图片后,虽然可以根据我们设置的图片精确显示tabBarItem图片,但是在开发过程中,我们经常需要设置文本属性,例如字体和字号tabBarItem集的标题. 要设置tabBarItem的文本属性,我们还有两种解决方案:
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-181949-1.html
伊拉克依靠美国反恐只能越反越恐