iOS viewController添加导航条添加跳转以及特效
来源:互联网 发布:萨斯喀彻温大学知乎 编辑:程序博客网 时间:2024/05/27 06:53
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
ViewController *mainView = [[ViewController alloc]init];
UINavigationController *navi = [[UINavigationController alloc]initWithRootViewController:mainView];
navi.navigationBar.backgroundColor = [UIColor blueColor];
[self.window setRootViewController:navi];
[self.window makeKeyAndVisible];
return YES;
}
self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:UITextAttributeTextColor]; // --- 字体颜色
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"BJ.png"] forBarMetrics:UIBarMetricsDefault]; // — 背景色
D=>A 有根视图的话 (HOME)
[self.navigationController popToRootViewControllerAnimated:YES];
D=>C (每一个界面返回上一层)
[self.navigationController popViewControllerAnimated:YES];
返回到上一层,并且传递参数
//此页面已经存在于self.navigationController.viewControllers中,并且是当前页面的前一页面
CViewController *cvc = [self.navigationController.viewControllers
objectAtIndex:self.navigationController.viewControllers.count-
2
];
CViewController *cvc = [CViewController alloc]init];
cvc.str = self.str;
[self.navigationController popToViewController:cvc animated:true];
返回到上一层后,上一页面显示后要接收参数,并刷新。注意此时应该在viewDidAppear中进行判断并接收传递的值
-(void)viewDidAppear:(BOOL)animated
{
//判断并接收返回的参数
}
NSArray *array = self.navigationController.viewControllers;
for (UIViewController *vc in array) {
if ([vc isKindOfClass:[BXXXViewController class]]) {
push VC;
}
或者知道每个界面的指针
[self.navigationController
popToViewController: [self.navigationController.viewControllers
objectAtIndex: ([self.navigationController.viewControllers count] -4)]
animated:YES];
在使用时,根据自己返回层的需要,只要改变一下“-4”这个数字就可以达到目的了
//=====2016年3月17日 增加导航条的变化 Xcode7.2
很多的应用现在都做到了,随着页面的滑动导航条的颜色也会发生变化,现在使用原生的导航条来体现一下基本原理。。。
*在项目属性里设置
View controller-based status bar appearance == NO 默认是YES
才可以改变导航条上20像素位置的状态栏颜色
干货:
本例使用的 UITableView 添加KVO实现监控滑动位置的变化
[_myTable addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew| NSKeyValueObservingOptionInitial context:nil];
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context
{
if ([keyPath isEqualToString:@"contentOffset"]) {
[self navChange];
}
}
-(void)navChange
{
if (_myTable.contentOffset.y <= 64) {
self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor blueColor] forKey:NSForegroundColorAttributeName];
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"BJ1.png"] forBarMetrics:UIBarMetricsDefault];
self.title = @"初始导航条";
}
else if (_myTable.contentOffset.y >= 192 )
{
self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName];
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"BJ2.png"] forBarMetrics:UIBarMetricsDefault];
self.title = @"导航条最终状态";
// 状态栏颜色为白色
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
}else
{
self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor redColor] forKey:NSForegroundColorAttributeName];
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"BJ3.png"] forBarMetrics:UIBarMetricsDefault];
self.title = @"导航条中间状态";
// 状态栏颜色为白色
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
}
}
上效果图 无图无真相
demo地址:https://github.com/Lian1990/NavColorRamp
- iOS viewController添加导航条添加跳转以及特效
- iOS 导航条上添加UISegmentedControl,点击分类按钮,显示不同的ViewController
- ios导航条添加按钮
- ios导航条添加按钮
- 为导航条添加按钮
- SharePoint添加顶部导航条
- iOS 之在一个viewController中添加多个viewController
- iOS 导航栏右侧添加图片以及监听
- iOS开发navigationBar导航条和navigationItem设置:基本搞定导航条上的文字和按钮以及各种跳转
- IOS开发:导航栏添加多个按钮以及在左边添加logo
- iOS添加左右导航按钮
- IOS 导航栏添加事件
- ios ViewController 页面跳转
- ios ViewController 页面跳转
- ios ViewController 页面跳转
- ios ViewController 页面跳转
- ios ViewController 页面跳转
- ios ViewController 页面跳转
- 51nod 欢乐手速场C 开心的小Q
- Java开发中的23种设计模式详解(转)
- httpd
- 百度通用搜索代码
- 前端优化:九个技巧,提高Web性能
- iOS viewController添加导航条添加跳转以及特效
- PAT BASIC 1013 数素数
- Android PopupWindow详解
- Android 6.0 - 动态权限管理的解决方案
- centos 上安装 postgresql 9.5
- JDK源码之解读String最终类的equals()和hashcode()方法实现原理
- kudu vs parquet, impala vs spark Benchmark
- AlphaBeta剪枝算法
- 解决node-sass安装失败的问题