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

首頁 > 系統(tǒng) > iOS > 正文

iOS viewController添加導(dǎo)航條添加跳轉(zhuǎn)以及特效

2019-11-09 16:42:07
字體:
供稿:網(wǎng)友
給單獨(dú)的viewcontroller或者在Appdelegate的主頁面添加導(dǎo)航條,只要在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;

}

導(dǎo)航條的字體和顏色的設(shè)置

self.navigationController.navigationBar.titleTextAttributes =  [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:UITextAttributeTextColor]; // --- 字體顏色

    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"BJ.png"] forBarMetrics:UIBarMetricsDefault]; // — 背景色

導(dǎo)航條跳轉(zhuǎn)頁面的考慮對于用navigationcontroller來跳轉(zhuǎn)頁面的時(shí)候,其實(shí)是執(zhí)行堆棧的進(jìn)棧和出棧的操作,要想釋放內(nèi)存,那么在來回跳轉(zhuǎn)的時(shí)候,就要考慮幾個(gè)問題了1 A =>B=>C=>D,D=>A 有根視圖的話 (HOME)[self.navigationController popToRootViewControllerAnimated:YES];  D=>C  (每一個(gè)界面返回上一層)[self.navigationController popViewControllerAnimated:YES];  返回到上一層,并且傳遞參數(shù)//此頁面已經(jīng)存在于self.navigationController.viewControllers中,并且是當(dāng)前頁面的前一頁面  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];返回到上一層后,上一頁面顯示后要接收參數(shù),并刷新。注意此時(shí)應(yīng)該在viewDidAppear中進(jìn)行判斷并接收傳遞的值-(void)viewDidAppear:(BOOL)animated{  //判斷并接收返回的參數(shù)}2  A =>B=>C=>D=>E,E=>B=>C=>E因?yàn)锽在之前已經(jīng)出現(xiàn)過,不能在E中直接PUSH到B,因?yàn)槟菢右呀?jīng)是兩個(gè)B了,增加內(nèi)存,所以在跳轉(zhuǎn)的時(shí)候,就要進(jìn)行判斷是否之前已經(jīng)出現(xiàn)過B了,出現(xiàn)過,則直接push。這樣push到的是原有的B,不會在內(nèi)存中重新生成一個(gè)B了。

 NSArray *array = self.navigationController.viewControllers;

    for (UIViewController *vc in array) {

        if ([vc isKindOfClass:[BXXXViewController class]]) {

push VC;

}

或者知道每個(gè)界面的指針

[self.navigationController 

popToViewController: [self.navigationController.viewControllers 

         objectAtIndex: ([self.navigationController.viewControllers count] -4)] 

                animated:YES]; 

在使用時(shí),根據(jù)自己返回層的需要,只要改變一下“-4”這個(gè)數(shù)字就可以達(dá)到目的了

//=====2016年3月17日 增加導(dǎo)航條的變化 Xcode7.2

很多的應(yīng)用現(xiàn)在都做到了,隨著頁面的滑動導(dǎo)航條的顏色也會發(fā)生變化,現(xiàn)在使用原生的導(dǎo)航條來體現(xiàn)一下基本原理。。。

*在項(xiàng)目屬性里設(shè)置  

View controller-based status bar appearance == NO 默認(rèn)是YES

才可以改變導(dǎo)航條上20像素位置的狀態(tài)欄顏色

干貨:

本例使用的 UITableView 添加KVO實(shí)現(xiàn)監(jiān)控滑動位置的變化

[_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 = @"初始導(dǎo)航條";    }    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 = @"導(dǎo)航條最終狀態(tài)";        // 狀態(tài)欄顏色為白色        [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 = @"導(dǎo)航條中間狀態(tài)";        // 狀態(tài)欄顏色為白色        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;    }}

上效果圖 無圖無真相

  

demo地址:https://github.com/Lian1990/NavColorRamp


發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 兴仁县| 清流县| 山丹县| 阿图什市| 内江市| 沅陵县| 秦皇岛市| 锡林郭勒盟| 喀什市| 临颍县| 阿尔山市| 布尔津县| 宝丰县| 河东区| 巧家县| 壶关县| 宁国市| 旬邑县| 满洲里市| 南乐县| 邵阳县| 崇信县| 承德市| 阿鲁科尔沁旗| 全州县| 灵山县| 嘉鱼县| 宜宾市| 南丹县| 民县| 嘉定区| 偏关县| 尼玛县| 静宁县| 凌云县| 黄骅市| 新蔡县| 嘉义市| 五寨县| 三门县| 曲阜市|