0829-0607 UITabBarController-QQ框架界面搭建
0829-0607归档
NSKeyedArchever保存数据到Documents中 实际开发中会使用SQLite3 推荐的方式 因为数据量大 SQLite3性能好
这里 我们使用的是:
登录界面使用NSUserDefaults
联系人界面使用 NSkeyedArchiver
----------------------
UITabBarController
使用步骤
1、将控制器的视图交给self.window.rootViewController = tbVc (view高度480 并有子控制器tabBar 高度49)
2、tbVc addChildViewController:vc1(UIViewController) 或者tbVc.viewControllers = @[vc1,vc2]
运行程序点击navigationBar上item的时候 是执行的push操作
UITabBarController *tb1 = [[UITabBarController alloc] init];
self.window.rootViewController =tb1; 将tabBarController的.view交给 self.window.view
// tb1.view{{0, 0}, {320, 480}}
// tb1.view addSubview:子控制器的view {{0, 0}, {320, 480}} ios6里面的高度是431
// tb1.view addSubview:tb1.tabBar {{0, 431}, {320, 49}}
tabBarController添加自控制器的时候 会将第一个子自控制器最先显示 其他自控制器在点击下面的tabBar上的某个item的时候显示
tb1.viewControllers = @[vc1,vc2] //vc1=UIViewController vc1.tabBarItem.title = @"联系人" vc1默认有tabBarItem
vc1.tabBarController.tabBar
tb1.tabBar.items tb1.tabBar.subviews
UITabBarItem 属性包括 title image selectedImage badgeValue (如10)
appDelegate.m里
self.window makeKeyAndVisible 是成为application的主窗口 application.keyWindow
- (void)applicationDidBecomeActive:(UIApplication *)application
里面 开始创建主窗口
// HMAppDelegate.m // UITabBarController-空项目 #import "HMAppDelegate.h" @implementation HMAppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. self.window.backgroundColor = [UIColor whiteColor]; UITabBarController *tab = [[UITabBarController alloc] init]; self.window.rootViewController = tab; UIViewController *vc1 = [[UIViewController alloc] init]; vc1.view.backgroundColor = [UIColor redColor]; vc1.tabBarItem.title = @"消息"; vc1.tabBarItem.image = [UIImage imageNamed:@"tab_recent_nor"]; // [tab addChildViewController:vc1]; UIViewController *vc2 = [[UIViewController alloc] init]; vc2.view.backgroundColor = [UIColor redColor]; vc2.tabBarItem.title = @"联系人"; vc2.tabBarItem.image = [UIImage imageNamed:@"tab_buddy_nor"]; vc2.view.backgroundColor = [UIColor greenColor]; // [tab addChildViewController:vc2]; UIViewController *vc3 = [[UIViewController alloc] init]; vc3.view.backgroundColor = [UIColor redColor]; vc3.tabBarItem.title = @"动态"; vc3.tabBarItem.image = [UIImage imageNamed:@"tab_qworld_nor"]; vc3.view.backgroundColor = [UIColor blueColor]; // [tab addChildViewController:vc3]; tab.viewControllers = @[vc1,vc2,vc3]; [self.window makeKeyAndVisible]; return YES; }
-----------------
UITabBarController的拖storyboard
1、拖UITabBarController 删除2个UIViewController控件
2、自己拖一个UIViewController控件vc1
3、右键UITabBarController 看到view controllers 拖到vc1上面
--------
应用程序进入后台休眠 不接收事件
Command +Shift + 2此点击H 程序进入后台后
应用程序里面的所有事件都不接收 这是后向上推把程序关闭也不会调用下面的方法
音乐播放器后面会讲到进入后台不要进入休眠状态
---------------
QQ框架界面搭建(主流)
现有TabBarController 后有navigationController
有了这个可以自己搭建很多种框架了
1、storyboard搭建界面 先删除viewController控件 自己拖一个TabBarController(属性设置为启动控制器init view controller) 删除TabBarController指向的2个ViewController
2、拖几个NavigationController
3、右键TabBarController 找到viewControllers 连线几个NavigationController 这时候所有的navigatinController下面会显示他的navigationItem 设置每个navigationItem的值
为联系人、消息、
4、设置每个navigationController控件push的 UIViewController 头部的navigationBar 左边右边各加一个 UIBarButtonItem
5、设置其中一个UITableViewController的静态单元格 先分组模式 然后设置3组 每一组的cell ctrl + c ctrl +v 设置几行
拖动第一个cell把这个cell拉高一点
第某个cell设置style为right detail , 然后设置 lines为0 (multi lines =0 表示换行),修改里面的文字 再拉高cell
6、新建一个tableViewController tv111,选择某个cell push到tv111 tv111的头部-tablewHeaerView放一个UIView 里面拖一个UIImageView 和一个 UILabel
tv111设置 勾选Hide Bottom Bar On Push
7、代码创建控制器 storyboard中的控制器与其对应 这里新创建的FFAddTableViewController 默认创建的时候 -numberofrowsInSection** -numberOf*** 都是 return 0
而stroyboard里的 tableViewController是静态单元格 所以需要删除这2个方法
先有UITabBarController tb.viewControllers = 几个导航控制器 (导航控制器继承UIViewController和其实平级的 只是在push的时候会共享一个navigationbar)
vc1.navigationItem setLeftBarButtonItems设置左边的一些barButtonItem
vc1.navigationItem setLeftBarButtonItem设置左边的barButtomItem
------------
QQ框架界面搭建(非主流 )
有缺陷 所以一般不适用这种搭建结构
现有UINavigationController 后有 UITabBarController
1、清空stroyboard中原有的控制器 拖一个UINavigationController
2、UINavigationController原有的UIViewController 拖一个UITabBarConroller tbVc1
3、右击UINavigationController设置 rootViewController 为tbVc1
4、设置tbVc1的自控制器控件的属性item字体 iamgeView selectedImageView badgedNumber
-----------
其他:
[view1 isKindOfclass:[UIImageView class]] 判断是否是UIImageView
[view1 isMemberOfclass:[UIImageView class]] 判断是否是UIImageView或者UIImageView的子类
self.parentViewController
--------------------------------------------------
自定义tabBar
补充来源 (二期0616-0617)
storyboard一个tabbarController 5个navigationController 拖线
美 工提供的图片是图文混合的(文字不想要 但是只设置图片 不设置文字不行(在storyboard->uibabbarController->navigationController 的 tabbar item上设置图片 没有文字是不行的)) 所以要自定义tabbar 替换系统的tabbar 并且移除系统的tabbar (让navigationController的tabbar item设置无效)
不在storyboard里设置 每个tabbar item
@implementation NJTabBarController
- (void)viewDidLoad
{
[super viewDidLoad];
// 1.创建自定义的TabBar
NJTabBar *myTabBar = [[NJTabBar alloc] init];//代码init会创建自动调用initWithFrame initWithFrame方法 创建和添加子控件(自定义Button 设置一些初始状态值)
并且在NJTabBar的layoutSubviews里初始化子控件(自定义button的)的frame (注意一定要这样写 如果直接在initWithFrame方法里直接设置子空间的frame值 会导致子空间的frame还是{(0,0),(0,0)})
// myTabBar.backgroundColor = [UIColor greenColor];
myTabBar.frame = self.tabBar.frame;//将系统的tabBar.frame交给自动以的frame
myTabBar.delegate = self;// myTabBar加代理人为NJTabBarController 控制器 准备通知NJTabBarController切换控制器
[self.view addSubview:myTabBar];
// 2.删除系统自带的tabBar
[self.tabBar removeFromSuperview];
自定义用自定义NJtabBar代替navController.tabBar 有一个好处 就是在6.1 和7.1的系统上都可以正常显示 如果不自定义tabBar在6系统很难看
UIControlStateDisabled方法
自定义myButton继承UIButton 重写按下(还没抬起来)父类UIButton setHighlight方法将自己变灰了
所以muButton要重写 UIButton的 setHightLight方法 让这个方法设置空操作
#import "NJTabBarButton.h"
@implementation NJTabBarButton
- (void)setHighlighted:(BOOL)highlighted
{
// NSLog(@"setHighlighted");
// [super setHighlighted:highlighted];
}
@end
NJtabBar(里面添加了几个自定义button) 点击button button通知tabbarController去切换控制器 修改其selectedIndex
批量设置导航条背景色:
不让push出去的控制器来管理各自的导航条的背景图片
------
打印当前系统版本号 是6.1还是7.1系统