现在的位置: 首页 > 综合 > 正文

UINavigationController,UINavigationBar

2013年09月06日 ⁄ 综合 ⁄ 共 5404字 ⁄ 字号 评论关闭

1.UINavigationController是用于构建分层应用程序的主要工具,它维护了一个视图控制器栈,任何类型的视图控制器都可以放入.

  它在管理,以及换入和换出多个内容视图方面,与UITabBarController(标签控制器)类似. 两者间的主要不同在于: UINavigationController是作为栈来实现,它更适合用于处理分层数据.

 它还有一个作用是用作顶部菜单。

2. 根控制器,子控制器.

    在设计导航控制器时,需要指定用户看到的第一个视图,该视图处在导航栈的最底层,其对应的控制器称为根控制器.所以不要把根控制器理解为导航控制器.根控制器也是导航控制器的一个子控制器.

    在术语上把栈中的除了根控制器其余的控制器称为子控制器.

    一般地,根控制器对应的视图上有各个子控制器视图的入口,回退到根视图然后再切换各个子视图.

    默认地,导航控制器会自动在当前子控制器对应视图的导航栏的右端加一个返回按钮,名称是上一个视图的标题.

 

3. 导航按钮.

   导航按钮类似于网页上的后退按钮,当点击时,当前的视图控制器出栈,栈中的下一个视图成为当前视图.

 

4. 其它术语:

    扩展图标(accessory icon)称为扩展指示器(disclosure indicator),告知将切换到另一个视图,它以一个灰色箭头表示.

    细节展示按钮(detail disclosure button)不仅是一个图标,它还是一个可单击的控件.

 

5.静态使用UINavigationController

   <<iphone开发基础教程>>第9章,新建window-based application,使用IB向mainwindow.xib添加了一个UINavigationController,

 

6.控制器与其成员间的关系

(1).UINavigationController

主要成员:

   UINavigationBar *navigationBar;应该是管理了所有子控制器的navigationItem,显示在窗口顶部;

   UIToolbar *toolbar;工具栏,显示在窗口底部;

(2).UINavigationBar管理了一组 UINavigationItem.

     navigationBar.frame.size.height=44;

 

(4).UITabBar管理了一组 UITabBarItem.

     UITabBarController

     tabBar.frame.size.height=49;

 

(5).UIViewController提供了基础的view管理模型.

  主要成员:

  UINavigationItem *navigationItem;用于展现视图控制,第一次被访问时创建,被添加到一个navigationBar中.

  NSArray *toolbarItems;一组UIBarButtonItem,被添加到一个toolBar中.

  UITabBarItem *tabBarItem;被添加到一个tabBar中.

 

(6).UINavigationItem是一个视图顶部上的导航条

   有如下主要成员:

   UIView* titleView:显示在导航栏中间.有解释说This property is ignored if leftBarButtonItem is not nil.,使用后发现不是这样的.

   UIBarButtonItem *leftBarButtonItem

   UIBarButtonItem *rightBarButtonItem

   系统的刷新图标,但是它带有边框。

   self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refresh)];
   

   NavigationController导航栏中添加多个UIBarButtonItem
   http://wangjun.easymorse.com/?p=975

 

(7).UIBarButtonItem封装了一些属性和行为,它被添加到UIToolBar中.

   主要成员

   SEL action;

   UIView* customView;

 

7.一些高级控制器

  UIImagePickerController,

  UITableViewController,

 

8.http://blog.zhaojie.me/2010/12/iphone-composition-resistant-uitabbarcontroller.html

   发现UITabBarController不能放入其他的视图内,而只能直接放在Window上(或Window里的UINavigationController里),否则会出现界面向下偏移的情况。对于UITabBarController抗拒组合的情况,深表叹息。

  并且UITabBarController中的tabBar如何隐藏??

 

9.在UIViewController中访问导航:

    通常在UIViewController的子类中调用self.navigationController来调用视图的推入和弹出。不能弹出根,

    要改变导航栏的样式或颜色,访问self.navigationController.navigationBar

    要改变上面的左右按钮或标题内容,访问self.navigationItem,它描述导航栏上的控件内容。

10.UINavigationItem:

     UINavigationItem存储导航项属性,包括:左右按钮,标题,标题视图,返回本页的按钮。还有一个prompt,以导航栏上方再显示一行提示,把导航栏位置向下挤。

    参考http://www.cnblogs.com/smileEvday/archive/2012/05/14/2495153.html

 11.定制标题的3种方法:

     self.title=@"标题文字";self.title=[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];

     self.navigationItem.title=@"标题文字"

     self.navigationItem.titleView=

12.在UIViewController中,使用self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.20392f green:0.19607f blue:0.61176f alpha:1.0f];改变导航栏的颜色,它会形成以中间向上下两边的渐变。其它颜色值不确定能否形成这样的效果。

     使用self.navigationItem.rightBarButtonItem等控制导航栏上面的内容。

13.可以继承出一个UINavigationController的子类 ,重写pushViewController,popViewControllerAnimated方法,

     比如可以实现点击默认返回按钮时,二次确认是否执行返回操作。

 

14.presentModalViewController弹出一个UIViewController时,可能需要它有导航栏,以摆放功能按钮。

    只要再包一层UINavigationController即可。

        LocalPhotoViewController* viewController=[[LocalPhotoViewController alloc] initWithImageArray:arr currentIndex:0];
        UINavigationController* nav=[[UINavigationController alloc] initWithRootViewController:viewController];
        [self presentModalViewController:nav animated:YES];
        [nav release];
        [viewController release];

        取消时使用[self dismissModalViewControllerAnimated:YES];,viewController在内部执行这个也有效。

15.半透明下沿:

      (1)第一种方法是:换背景,可以使用比标题栏高的背景图片,在UINavigationBar的drawrect中,把它向下延伸一点画出来,可以达到最下边有层半透明的效果。

          ios5中有可以直接修改背景图片的属性了。?

     (2)第二种方法是:操作layer,加下阴影

     #import "QuartzCore/CALayer.h"

     CALayer* navLayer = self.navigationController.navigationBar.layer;
    navLayer.masksToBounds = NO;
    navLayer.shadowColor = [UIColor blackColor].CGColor;
    navLayer.shadowOffset = CGSizeMake(0.0, 5.0);
    navLayer.shadowOpacity = 0.25f;
    navLayer.shouldRasterize = YES;//加了这句,可能会导致导航栏内容错乱。

 

16.修改导航bar的高度,使用类别重写)layoutSubviews方法

@implementation UINavigationBar (CustomHeight)

- (void)layoutSubviews {
  [super layoutSubviews];
  CGRect barFrame = self.frame;
  barFrame.size.height = height;
  self.frame = barFrame;
}

@end

 

17.如果在push后立即pop,若使用了animited,则要延0.4秒再pop,否则可能会导航变为了上一层的,而内容还是本层的。如果animited为NO,则可以立即pop。

 

18.实现pushViewController:animated:的不同页面转换特效
     首先要不使用pushViewController的默认动画,在调用时将animated设置为NO.
     使用普通的来CATransition实现转换效果,示例代码如下:
    CATransition *animation = [CATransition animation];
    [animation setDuration:0.3];
    [animation setType: kCATransitionMoveIn];
    [animation setSubtype: kCATransitionFromTop];
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];
    [self.navigationController pushViewController:m_poseAddIssueViewController animated:NO];
    [self.navigationController.view.layer addAnimation:animation forKey:nil];

19.popToViewController 跳过前面的controller,实现多级回退。

20.若要使用自定义的UINavigationBar,先实现自定义的UINavigationBar,例如命名为CustomNavigationBar,然后使用类别重写如下方法:

@implementation UINavigationBar (CustomImage)
+ (Class)class
{
    return NSClassFromString(@"CustomNavigationBar");
}

- (void) drawRect: (CGRect)rect
{
}
@end

然后在CustomNavigationBar的drawRect中要增加判断,使UIImagePickerController等使用系统默认的风格,如下:

- (void)drawRect:(CGRect)rect
{
    if([self.delegate isKindOfClass:[UIImagePickerController class]])
    {
       [super drawRect:rect];
        return;
    }

     ........
}

21.

抱歉!评论已关闭.