Q
隱形導航欄
0
A
回答
3
要獲得一個UINavigationBar的或UIToolbar一個透明背景,您必須將背景色設置爲[UIColor clearColor]
,設置opaque
爲NO(如果沒有的話),並覆蓋drawRect
不繪製標準漸變背景。第三個是棘手的部分。
如果您直接使用UINavigationBar,您可以很容易地將其子類化,以覆蓋drawRect
。但我看到你用UINavigation Controller標記了這個,所以你必須嘗試用一個類別覆蓋它。像這樣的東西應該這樣做:
@implementation UINavigationBar (invisibleBackground)
- (void)drawRect:(CGRect)rect {}
@end
這具有以下缺點:在您的應用程序的每個導航欄現在有沒有背景。如果你希望能夠有一些透明和一些正常的,你必須去一步,調酒drawRect
所以在需要的時候可以調用原:
#import <objc/runtime.h>
@implementation UINavigationBar (invisibleBackgroundSwizzle)
// The implementation of this method will be used to replace the stock "drawRect:". The old
// implementation of "drawRect:" will be attached to this name so we can call it when needed.
- (void)replacementDrawRect:(CGRect)rect {
if (![self.backgroundColor isEqual:[UIColor clearColor]]) {
// Non-transparent background, call the original method (which now exists
// under the name "replacementDrawRect:"). Yes, it's a bit confusing.
[self replacementDrawRect:rect];
} else {
// Transparent background, do nothing
}
}
// This special method is called by the runtime when this category is first loaded.
+ (void)load {
// This code takes the "drawRect:" and "replacementDrawRect:" methods and switches
// thier implementations, so the name "drawRect" will now refer to the method declared as
// "replacementDrawRect:" above and the name "replacementDrawRect:" will now refer
// to the original implementation of "drawRect:".
Method originalMethod = class_getInstanceMethod(self, @selector(drawRect:));
Method overrideMethod = class_getInstanceMethod(self, @selector(replacementDrawRect:));
if (class_addMethod(self, @selector(drawRect:), method_getImplementation(overrideMethod), method_getTypeEncoding(overrideMethod))) {
class_replaceMethod(self, @selector(replacementDrawRect:), method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod));
} else {
method_exchangeImplementations(originalMethod, overrideMethod);
}
}
@end
0
相關問題
- 1. 製作的導航欄邊框隱形
- 2. 隱藏導航欄
- 3. 隱藏導航欄?
- 4. 隱藏導航欄
- 5. 隱藏導航欄
- 6. 隱藏導航條,顯示導航欄
- 7. UISearchDisplayController隱藏導航欄
- 8. 保持導航欄隱藏
- 9. SWIFT:導航欄不隱藏
- 10. Nativescript - 隱藏導航欄(IOS)
- 11. 隱藏導航欄像facebook
- 12. 如何隱藏導航欄?
- 13. React Native - 隱藏導航欄
- 14. FBUserSettingsViewController隱藏導航欄
- 15. 隱藏導航欄永久
- 16. GMSMapView中隱藏導航欄
- 17. 導航欄隱藏錨點
- 18. 如何隱藏導航欄?
- 19. 隱藏導航欄旋轉
- 20. 標籤導航欄隱藏
- 21. 隱藏導航欄標題
- 22. IPHONE:ABPeoplePickerNavigationController隱藏導航欄
- 23. 問題隱藏導航欄
- 24. SFSafariViewController:隱藏導航欄
- 25. 導航欄狀態,顯示和隱藏底部導航欄
- 26. iOS導航欄:隱藏導航欄和平滑過渡
- 27. 導航欄圖片隱藏自定義導航欄按鈕
- 28. 導航欄中的標籤欄隱藏
- 29. 隱藏標籤欄和導航欄
- 30. UITableViewController隱藏導航欄[搜索欄]
謝謝smallduck!偉大的閱讀。 – 2011-03-11 23:20:13