IOS疯狂基础之UINavigationController
2013-03-14 14:52
423 查看
常用代码收集:
UIView * tview = [[UIView
alloc]initWithFrame:CGRectMake(0,
0, 150,
25)];
UIImageView * titleView = [[UIImageView
alloc]initWithImage:[UIImage
imageNamed:@"mainTitle.png"]];
[titleView
setFrame:CGRectMake(0,
0, 150,
22)];
[tview
addSubview:titleView];
self.navigationItem.titleView=tview;
创建一个navigationController 并给他个视图控制器
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]];
//设定标题
self.title = @"首页";
//修改为自定义图片 源码例子可以去我那资源里下载
采用继承自UINavigationController 然后重写 - (void)drawRect:(CGRect)rect
隐藏NavigationBar
[self.navigationController setNavigationBarHidden:YES animated:YES];
navigation的推转动画是可以更改的
CATransition *transition = [CATransitionanimation];
transition.duration = 0.3;
transition.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionDefault];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromLeft;
[self.navigationController.view.layeraddAnimation:transition forKey:nil];
[self.navigationControllerpopViewControllerAnimated:NO];
navigaiton的出栈有这么几种方式:
[self.navigationController popViewControllerAnimated:YES]; //回到上一个视图控制器
[self.navigationController popToViewController:viewController animated:YES];
//回到某一个视图控制器
[self.navigationController popToViewController: [self.navigationController.viewControllers objectAtIndex: ([self.navigationController.viewControllers count] -层次)] animated:YES];
[self.navigationController popToRootViewControllerAnimated:YES];
//回到根视图控制器
用了UINavigationController后,viewWillAppear方法是没有效果的,要用UINavigationControllerDelegate的
– navigationController:willShowViewController:animated: 方法才可以达到这个目的。
所以要做到这个,你必须做以下几步:
1. 设置代理类 nav.delegate = self;
2. 代理类实现UINavigationControllerDelegate Protocol
3. 在代理类中添加– navigationController:willShowViewController:animated:方法
如:
[html] view
plaincopy
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
[self.myTableView reloadData];
}
//设置Navigation Bar颜色 self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:(218.0/255.0) green:(228.0 / 255.0) blue:(250.0 / 255.0) alpha:1];
//自定义标题 titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0 , 100, 44)]; titleLabel.backgroundColor = [UIColor clearColor]; //设置Label背景透明 titleLabel.font = [UIFont boldSystemFontOfSize:20]; //设置文本字体与大小 titleLabel.textColor = [UIColor colorWithRed:(0.0/255.0) green:(255.0 / 255.0) blue:(0.0 / 255.0) alpha:1]; //设置文本颜色 titleLabel.textAlignment = UITextAlignmentCenter; titleLabel.text = @"自定义标题"; //设置标题 self.navigationItem.titleView = self.titleLabel;
UIView * tview = [[UIView
alloc]initWithFrame:CGRectMake(0,
0, 150,
25)];
UIImageView * titleView = [[UIImageView
alloc]initWithImage:[UIImage
imageNamed:@"mainTitle.png"]];
[titleView
setFrame:CGRectMake(0,
0, 150,
22)];
[tview
addSubview:titleView];
self.navigationItem.titleView=tview;
创建一个navigationController 并给他个视图控制器
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]];
//设定标题
self.title = @"首页";
//修改为自定义图片 源码例子可以去我那资源里下载
采用继承自UINavigationController 然后重写 - (void)drawRect:(CGRect)rect
隐藏NavigationBar
[self.navigationController setNavigationBarHidden:YES animated:YES];
navigation的推转动画是可以更改的
CATransition *transition = [CATransitionanimation];
transition.duration = 0.3;
transition.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionDefault];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromLeft;
[self.navigationController.view.layeraddAnimation:transition forKey:nil];
[self.navigationControllerpopViewControllerAnimated:NO];
navigaiton的出栈有这么几种方式:
[self.navigationController popViewControllerAnimated:YES]; //回到上一个视图控制器
[self.navigationController popToViewController:viewController animated:YES];
//回到某一个视图控制器
[self.navigationController popToViewController: [self.navigationController.viewControllers objectAtIndex: ([self.navigationController.viewControllers count] -层次)] animated:YES];
[self.navigationController popToRootViewControllerAnimated:YES];
//回到根视图控制器
用了UINavigationController后,viewWillAppear方法是没有效果的,要用UINavigationControllerDelegate的
– navigationController:willShowViewController:animated: 方法才可以达到这个目的。
所以要做到这个,你必须做以下几步:
1. 设置代理类 nav.delegate = self;
2. 代理类实现UINavigationControllerDelegate Protocol
3. 在代理类中添加– navigationController:willShowViewController:animated:方法
如:
[html] view
plaincopy
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
[self.myTableView reloadData];
}
相关文章推荐
- IOS疯狂基础之UILabel属性
- iOS 疯狂基础之NSDate 时间
- 疯狂iOS 讲义(上) Objective-C 2.0与iPhone/iPad应用开发基础(国内首部iOS 7相关著作,小伙伴们,学好iPhone/iPad应用开发,我们一起做土豪吧)
- IOS疯狂基础之多线程编程NSThread
- IOS疯狂基础之 载入子视图
- IOS疯狂基础之NSURL
- IOS疯狂基础之-动画Animations
- IOS疯狂基础之常见小效果
- IOS疯狂基础之MessageUI—短信
- IOS疯狂基础之NSDictionary
- IOS疯狂基础之NSNotificationCenter消息注册与撤销
- IOS疯狂基础之 UITextView 自动调整高度
- IOS疯狂基础之 通讯录
- IOS疯狂基础之网络检测
- IOS疯狂基础之隐藏系统键盘
- 疯狂iOS 讲义(上) Objective-C 2.0与iPhone/iPad应用开发基础
- IOS疯狂基础之GIF图片的显示
- IOS 疯狂基础之 页面间跳转
- IOS疯狂基础之NSUserDefaults
- IOS疯狂基础之UIImage