根据具体情况,通过push方法添加对应个数的子控制器
UINavigationController以栈的形式保存子控制器
使用push方法能将某个控制器压入栈
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated; //使用pop方法可以移除控制器 //将栈顶的控制器移除 - (UIViewController *)popViewControllerAnimated:(BOOL)animated; //回到指定的子控制器 - (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated; //回到根控制器(栈底控制器) - (NSArray *)popToRootViewControllerAnimated:(BOOL)animated;
UINavigationItem有以下属性影响着导航栏的内容
//左上角的返回按钮 @property(nonatomic,retain) UIBarButtonItem *backBarButtonItem; //中间的标题视图 @property(nonatomic,retain) UIView *titleView; //中间的标题文字 @property(nonatomic,copy) NSString *title; //左上角的视图 @property(nonatomic,retain) UIBarButtonItem *leftBarButtonItem; UIBarButtonItem *rightBarButtonItem //右上角的视图 @property(nonatomic,retain) UIBarButtonItem *rightBarButtonItem;
// 清空导航条背景图片,系统判断当前是否为Nil,如果为nil,系统还是会自动生成一张背景图片 [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault]; [self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
代码改变图片原始颜色
设置不被渲染
[image imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal]
self.automaticallyAdjustsScrollViewInsets = NO;
//每一个Segue对象,都有3个属性 //唯一标识 @property (nonatomic, readonly) NSString *identifier; //来源控制器 @property (nonatomic, readonly) id sourceViewController; //目标控制器 @property (nonatomic, readonly) id destinationViewController;
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender; // 这个sender是当初performSegueWithIdentifier:sender:中传入的sender
任何控制器都能通过Modal的形式展示出来
Modal的默认效果:新控制器从屏幕的最底部往上钻,直到盖住之前的控制器为止
//以Modal的形式展示控制器 - (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^)(void))completion 关闭当初Modal出来的控制器 - (void)dismissViewControllerAnimated: (BOOL)flag completion: (void (^)(void))completion;
//如果一个控制器的View显示在界面上,一定要把这个控制器强引用 //1. 首先创建一个当前控制器将要跳转到的控制器 YLViewController *VC = [[YLViewController alloc] init]; //2.把Modal的控制器的View添加到窗口上,把之前的窗口上的View移除 UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow; [keyWindow addSubview:VC]; //3.改形变属性,控制一个控件的位置(translation),尺寸(scale),角度(rotation) VC.view.transform = CGAffineTransformMakeTranslation(0,self.view.bounds.size.height); //4.动画向上推出 [UIView animateWithDuration:0.5 animations:^{ //CGAffineTransformIdentity:形变全部清空 VC.view.transform = CGAffineTransformIdentity; }completion:^(BOOL finished){ [self.view removeFromSuperview]; }];