国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

iOS viewController添加導航條添加跳轉以及特效

2019-11-09 17:44:52
字體:
來源:轉載
供稿:網友
給單獨的viewcontroller或者在Appdelegate的主頁面添加導航條,只要在viewcontroller上添加navigationcontroller,在添加此navigationcontroller即可

- (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]; // — 背景色

導航條跳轉頁面的考慮對于用navigationcontroller來跳轉頁面的時候,其實是執行堆棧的進棧和出棧的操作,要想釋放內存,那么在來回跳轉的時候,就要考慮幾個問題了1 A =>B=>C=>D,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{  //判斷并接收返回的參數}2  A =>B=>C=>D=>E,E=>B=>C=>E因為B在之前已經出現過,不能在E中直接PUSH到B,因為那樣已經是兩個B了,增加內存,所以在跳轉的時候,就要進行判斷是否之前已經出現過B了,出現過,則直接push。這樣push到的是原有的B,不會在內存中重新生成一個B了。

 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


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 鸡西市| 凯里市| 寻乌县| 白银市| 章丘市| 新邵县| 皮山县| 綦江县| 宁南县| 资阳市| 长兴县| 方山县| 花垣县| 昂仁县| 榆林市| 昌宁县| 文山县| 清徐县| 临夏市| 洛川县| 涟源市| 航空| 东山县| 蓝田县| 永济市| 翁源县| 峨边| 怀远县| 竹北市| 通化县| 青田县| 绥宁县| 光泽县| 武川县| 景德镇市| 阿拉善右旗| 芒康县| 崇礼县| 霍林郭勒市| 顺义区| 枝江市|