在點擊push下一個頁面時,因為各種原因,點一下cell或按鈕沒有響應(yīng),用戶可能就多點幾下,這時候會打開好幾個一樣的頁面。
創(chuàng)新互聯(lián)建站始終堅持【策劃先行,效果至上】的經(jīng)營理念,通過多達十余年累計超上千家客戶的網(wǎng)站建設(shè)總結(jié)了一套系統(tǒng)有效的推廣解決方案,現(xiàn)已廣泛運用于各行各業(yè)的客戶,其中包括:成都除甲醛等企業(yè),備受客戶認可。
這是因為push后的頁面有耗時操作或者剛好push到另一個頁面時,另一個頁面正好在reloadData卡住主線程。造成點擊cell時卡住了。
這時,我們可以通過重寫導(dǎo)航控制器的方法來解決這個問題。
#import UIKit/UIKit.h
@interfaceNaviViewController?:?UINavigationController
@end
#import "NaviViewController.h"
@interfaceNaviViewController?()
//?記錄push標(biāo)志
@property(nonatomic,getter=isPushing)BOOLpushing;
@end
@implementationNaviViewController
-?(void)viewDidLoad?{
? ? ? [superviewDidLoad];
? ? ? ?self.delegate=self;
}
-?(void)pushViewController:(UIViewController*)viewControlleranimated:(BOOL)animated?{
? ? if(self.pushing==YES)?{
? ? ? ? ? ? ?NSLog(@"被攔截");
? ? ? ? ? ? ?return;
? ? }else{
? ? ? ? ? ? ?NSLog(@"push");
? ? ? ? ? ? ?self.pushing=YES;
? ? }
[superpushViewController:viewControlleranimated:animated];
}
#pragma?mark?-?UINavigationControllerDelegate
-(void)navigationController:(UINavigationController*)navigationControllerdidShowViewController:(UIViewController*)viewControlleranimated:(BOOL)animated?{
? ? ? ? ?self.pushing=NO;
}
@end
導(dǎo)航欄不同于其他view,簡單的設(shè)置alpha并不能達到預(yù)想的效果。我在多次嘗試之后得出一個最有效的方式。
簡單的讓導(dǎo)航欄變透明只需要設(shè)置下面三個屬性:
但是這樣做有個問題,就是返回按鈕和title一起變透明了,解決方法是不要通過alpha來改變透明度,而是通過改變backgroundImage的透明度來實現(xiàn)。如何改變圖片的透明度呢,送上一個方法,你只需要創(chuàng)建一個UIImage的分類,實現(xiàn)這個方法,在需要的時候引入這個分類就可以使用了。
這樣以來,你只需要將你需要的圖片(也許是一張純色)通過 setBackgroundImage:forBarMetrics: 方法設(shè)置為背景圖片即可。
通過view的滾動實現(xiàn)一開始navigationBar隱藏,然后漸顯的效果還難嗎?
不過你可能發(fā)現(xiàn),頁面剛剛顯示還沒有滾動的時候,導(dǎo)航欄又不透明了,如果你不幸遇到這種狀況,其實也很簡單
是不是非常簡單?喜歡的話記得點紅心??啊。也歡迎評論與我交流????
ios 開發(fā)中設(shè)置導(dǎo)航欄透明的方法:
說明:讓導(dǎo)航欄變透明只需要設(shè)置下面三個屬性即可。
[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc]init] forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:[[UIImage alloc]init]];
self.navigationController.navigationBar.alpha = 0;
但這樣做有個問題,就是返回按鈕和title一起變透明了,解決方法是不要通過alpha來改變透明度,而是通過改變backgroundImage的透明度來實現(xiàn)。如何改變圖片的透明度呢,送上一個方法,只需要創(chuàng)建一個UIImage的分類,實現(xiàn)這個方法,在需要的時候引入這個分類就可以使用了。
- (UIImage *)imageByApplyingAlpha:(CGFloat) alpha{
UIGraphicsBeginImageContextWithOptions(self.size, NO, 0.0f);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGRect area = CGRectMake(0, 0, self.size.width, self.size.height);
CGContextScaleCTM(ctx, 1, -1);
CGContextTranslateCTM(ctx, 0, -area.size.height);
CGContextSetBlendMode(ctx, kCGBlendModeMultiply);
CGContextSetAlpha(ctx, alpha);
CGContextDrawImage(ctx, area, self.CGImage);
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
最終設(shè)置效果還是通過alpha設(shè)置。
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
self.navigationController.navigationBar.alpha = 0;
}
Swift版導(dǎo)航欄適配參考
在iOS 13中給導(dǎo)航的 UINavigationBar 增加了 scrollEdgeAppearance 屬性應(yīng)用在iOS 14及更早版本的大標(biāo)題導(dǎo)航欄上,在iOS 15中 scrollEdgeAppearance 屬性適用于所有的導(dǎo)航欄
官方解釋:描述當(dāng)關(guān)聯(lián)的UIScrollView到達與導(dǎo)航條相鄰的邊緣(導(dǎo)航條的上邊緣)時要使用的導(dǎo)航條的外觀屬性。如果沒有設(shè)置,將使用修改后的standardAppearance
scrollEdgeAppearance 與 standardAppearance 一樣同屬于 UINavigationBarAppearance 類型 父類是 UIBarAppearance
其中影響導(dǎo)航欄顏色、陰影涉及到以下屬性
因為 scrollEdgeAppearance = nil ,當(dāng)前控制器如果使用有 ScrollView 類的控件,當(dāng) ScrollView 向上滾動時 scrollEdgeAppearance 會默認使用 standardAppearance 的屬性效果。所以 backgroundEffect 和 shadowColor 屬性需要顯式設(shè)置為nil,以防止 backgroundEffect、shadowColor 有顏色值影響導(dǎo)航欄透明效果。
下一篇:Swift版導(dǎo)航欄適配
PERFECT!
上一篇說到 自定義導(dǎo)航欄 ,若自定義的導(dǎo)航欄中設(shè)置了屬性translucent = NO(作用是去掉顏色渲染,若為YES,與你想要的顏色存在一點的色差),導(dǎo)航欄的透明度會遇到問題。
若我們需要設(shè)置導(dǎo)航欄透明:正常的情況下,我們只需要這么做:
標(biāo)題名稱:ios開發(fā)導(dǎo)航,ios軟件導(dǎo)航
新聞來源:http://jinyejixie.com/article46/dssochg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè)、網(wǎng)站收錄、自適應(yīng)網(wǎng)站、品牌網(wǎng)站制作、移動網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)