QQ侧边栏效果(UIViewController添加子视图控制器)
来源:互联网 发布:mac md文件阅读器 编辑:程序博客网 时间:2024/05/16 01:14
效果图:(菜单,出现菜单栏-_-就放了个button,再次点击菜单回来,点击橘色的button推送到一个新的界面)
思路:给UIViewController添加标签控制器,标签控制器上装两个导航控制器,点击导航控制器上左边的UIabrButtonItem改变标签控制器视图的坐标(大小),再次点击还原
(附加:点击橘色按钮,push一个页面,页面充满整个屏幕)
给UIView添加子视图控制器:
@interface ViewController () { UINavigationController *homenav; //导航控制器 UINavigationController *messagenav; //导航控制器 UITabBarController *redViewController;//标签控制器 CGPoint _point; //屏幕中心点坐标}
- (void)viewDidLoad { [super viewDidLoad]; [self menuView]; _point = self.view.center; redViewController = [[UITabBarController alloc]init]; redViewController.view.backgroundColor = [UIColor redColor]; //更改所有导航控制器颜色 [UINavigationBar appearance].barTintColor = [UIColor greenColor]; homenav = [[UINavigationController alloc]initWithRootViewController:[[HomeViewController alloc]init]]; messagenav = [[UINavigationController alloc]initWithRootViewController:[[MessageViewController alloc]init]]; homenav.navigationBar.translucent = NO; redViewController.view.layer.shadowOffset = CGSizeMake(-10, 0); redViewController.view.layer.shadowColor = [UIColor blackColor].CGColor; //默认不显示阴影,要改不透明度 redViewController.view.layer.shadowOpacity = 0.6; redViewController.viewControllers = @[homenav,messagenav]; //添加子视图控制器 [self addChildViewController:redViewController]; //视图添加到自己的视图上面 [self.view addSubview:redViewController.view];}
#pragma mark - 菜单- (void)menuView { UIView *meanuView = [[UIView alloc]initWithFrame:self.view.bounds]; meanuView.backgroundColor = [UIColor yellowColor]; [self.view addSubview:meanuView]; UIButton *button = [[UIButton alloc]init]; button.frame = CGRectMake(0,100, 100, 30); button.backgroundColor = [UIColor orangeColor]; [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside]; [meanuView addSubview:button]; }- (void)buttonPressed:(UIButton *)sender { sharedInfoCenter.showLeftMenuView = NO; [UIView animateWithDuration:0.2 animations:^{ redViewController.view.center = _point; redViewController.view.transform = CGAffineTransformIdentity; }]; NSLog(@"%@",redViewController.selectedViewController); UIViewController *detailViewController = [[UIViewController alloc]init]; detailViewController.title = redViewController.selectedViewController.title; detailViewController.view.backgroundColor = [UIColor whiteColor]; if ([redViewController.selectedViewController isKindOfClass:[UINavigationController class]]) { [((UINavigationController *)redViewController.selectedViewController) pushViewController:detailViewController animated:YES]; }}
baseViewController:
- (void)viewDidLoad { [super viewDidLoad]; //自定义视图 // UIBarButtonItem *leftItem = [UIBarButtonItem alloc]initWithCustomView:<#(UIView *)#> _point = self.view.center; UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithTitle:@"菜单" style:UIBarButtonItemStylePlain target:self action:@selector(barButtonItem:)]; self.navigationItem.leftBarButtonItem = leftItem;}- (void)barButtonItem:(UIBarButtonItem *)sender { //单例持有 sharedInfoCenter.showLeftMenuView = !sharedInfoCenter.showLeftMenuView; if (sharedInfoCenter.showLeftMenuView) { [UIView animateWithDuration:0.2 animations:^{ self.tabBarController.view.transform = CGAffineTransformMakeScale(0.8, 0.8); self.tabBarController.view.center = CGPointMake(_point.x + 140,_point.y); }]; }else { [UIView animateWithDuration:0.2 animations:^{ self.tabBarController.view.transform = CGAffineTransformIdentity; self.tabBarController.view.center = _point; }]; } }
0 0
- QQ侧边栏效果(UIViewController添加子视图控制器)
- UIViewController 的parent viewController(子视图控制器)
- iOS添加子视图控制器
- 视图控制器 ( UIViewController )
- UIViewController视图控制器
- UIViewController 视图控制器
- 视图控制器UIViewcontroller
- UI 视图控制器UIViewController
- UIViewController/视图控制器
- UIViewController视图控制器
- UIViewController 视图控制器
- 视图控制器---UIViewController介绍
- UI -视图控制器UIViewController
- UIViewController 视图控制器
- 【UIViewController视图控制器】
- 添加和移除子视图控制器(child ViewController)
- Android实现仿qq侧边栏效果
- Android实现仿qq侧边栏效果
- 2015年3月1日起停止提供4年或5年SSL证书
- 仿qq搜索动画效果
- 安装cocos2dx
- 深入探讨 Java 类加载器
- wordpress博客建站网赚高级应用系列教程
- QQ侧边栏效果(UIViewController添加子视图控制器)
- Python基于YCbCr 肤色模型的情色图片检测的简单实现
- jdk1.5高新技术(二)
- 几个opencv自带测试视频
- HDU-5135 广州现场赛题
- 答辩PPT注意事项
- LeetCode Sort List
- 最新wp建站做淘宝客系统教程(共6课)附源码
- 【hibernate框架】hibernate的ID的生成策略剖析