您的位置:首页 > 产品设计 > UI/UE

UINavigationController(导航控制器)及跳转页面的方法

2015-09-01 17:56 417 查看
[self.navigationController pushViewController:_registVC animated:YES];

一.UINavigationController(导航控制器)
UINavigationController可以控制多个UIViewController

1.初始化一个UINavigationController

<span style="font-size:14px;">self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
[self.window makeKeyAndVisible];

LoginViewController *loginVC = [[LoginViewController alloc]init];

UINavigationController *navigationVC = [[UINavigationController alloc]initWithRootViewController:loginVC];

self.window.rootViewController = navigationVC;</span>


2.添加UINavigation

//UIBarButtonItem继承于UIBarItem

//1.初始化一个UIBarButtonItem
UIBarButtonItem *btnItem = [[UIBarButtonItem alloc]initWithTitle:@"注册" style:UIBarButtonItemStyleDone target:self action:@selector(btnItemAction:)];

/*
//2.title:修改UIBarButtonItem的名称
btnItem.title = @"adklfj";

//3.enabled:标识UIBarButtonItem是否为可编辑,其默认值为YES.
btnItem.enabled = NO;

//4.image:给UIBarButtonItem设置一张图片
btnItem.image = [[UIImage imageNamed:@"zx"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
*/

//5.修改UINavigationController的title.
self.navigationItem.title = @"登陆";

//6.navigationBarHidden:隐藏navigationController的导航栏,默认值是NO
self.navigationController.navigationBarHidden = NO;

//7.//navigationBar:设置navigationBar.<span style="color:#FF0000;">translucent</span>(透明度)的值为NO,其默认值是YES;设置navigationBar的值为NO后,视图的(0,0)点就是在navigationBar的左下角.
self.navigationController.navigationBar.translucent = NO;


二.跳转页面的方法

1.从前往后跳转页面

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated;
// Uses a horizontal slide transition. Has no effect if the view controller is already in the stack.
例如:
[self.navigationController pushViewController:_registVC animated:YES];

2.从后往前跳转页面

//这个方法是返回前一个界面
- (UIViewController *)popViewControllerAnimated:(BOOL)animated;
// Returns the popped controller.

//这个方法是返回到在同一条链路上的任意一个界面
- (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated;
// Pops view controllers until the one specified is on top. Returns the popped controllers.

//这个方法是返回到根视图
- (NSArray *)popToRootViewControllerAnimated:(BOOL)animated;
// Pops until there's only a single view controller left on the stack. Returns the popped controllers.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: