No.06 Xcode(5.1.x) UINavigationController

1.在iOS7.0以上版本中, 如果UINavigationController作为UIWindow的根控制器, 顶部的导航栏会包含状态栏, 并且UINavigationController包含的子视图默认左上角与状态栏左上角对齐, 需要将translucent设置为NO才正常.

2.加入的子控制器, 都包含在childViewControllers属性中, 可以作为只读属性来查, 但是最好不要去更改它, 请用UINavigationController的接口去更改子视图

3.navigationBar是顶部的导航栏, 但是如果想要通过navigationBar.frame来获取导航栏的区域, 是不可行的, 通常使用硬编码来获取这个值:

  • 纵向模式为44像素;
  • 横向模式为32像素;
  • 提示模式为74像素(横向和纵向);

4.导航栏的左右键定制时, 建议使用[initWithCustomView:]方法, [initWithBarButtonSystemItem: target: action:]等方法难以定制按钮的外形

5.使用[pushViewController: animated:]等方法弹出或加入视图时, 可以将animated参数设置为NO, 然后在navigationController.view.layer上建立自定义动画


创建导航栏

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    ViewController* controller = [[ViewController alloc] init];
    
    UINavigationController* naviController = [[UINavigationController alloc] initWithRootViewController:controller];
    naviController.navigationBar.translucent = YES;
    naviController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys: [UIColor whiteColor], NSForegroundColorAttributeName, [UIFont systemFontOfSize:20.0], NSFontAttributeName, nil]; // 设置字体
    [naviController.navigationBar setBackgroundImage:[UIImage imageNamed:@"Ingredients/bg003.png"] forBarMetrics:UIBarMetricsDefault]; // 设置背景

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.rootViewController = naviController;
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

定制导航栏

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    // 定制右键
    UIButton* rtButton = [[UIButton alloc] initWithFrame:CGRectMake(0.0, 0.0, 80.0, 20.0)];
    [rtButton setBackgroundColor:[UIColor grayColor]];
    [rtButton setTitle:@"普通" forState:UIControlStateNormal];
    [rtButton setTitle:@"高亮" forState:UIControlStateHighlighted];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rtButton];
}

加入或弹出

- (void)popToPrev:(UIButton*)button
{
    CATransition* transition = [CATransition animation];
    transition.duration = 1.0;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type = @"cube";
    transition.subtype = kCATransitionFromLeft;
    transition.delegate = self;
    [self.navigationController.view.layer addAnimation:transition forKey:@"animationxxxx"];
    
    [self.navigationController popViewControllerAnimated:NO];
}

- (void)popToSome:(UIButton*)button
{
    UIViewController* controller = [self.navigationController.childViewControllers objectAtIndex:0];
    [self.navigationController popToViewController:controller animated:YES];
}

- (void)popToRoof:(UIButton*)button
{
    [self.navigationController popToRootViewControllerAnimated:YES];
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值