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. SFSafariViewController:隐藏导航栏
- 6. 如何隐藏导航栏?
- 7. IPHONE:ABPeoplePickerNavigationController隐藏导航栏
- 8. Nativescript - 隐藏导航栏(IOS)
- 9. 导航栏图片隐藏自定义导航栏按钮
- 10. iOS导航栏:隐藏导航栏和平滑过渡
- 11. UITableViewController隐藏导航栏[搜索栏]
- 12. 从标签栏控制器导航栏隐藏孩子的导航栏
- 13. 侧栏导航改为导航栏中的顶部导航栏
- 14. 在flex中隐藏导航栏
- 15. 加速器钛 - 隐藏导航栏android
- 16. 如何隐藏lightSlder的导航栏?
- 17. uinavigationcontroller导航栏始终隐藏
- 18. 隐藏导航栏不工作
- 19. 无法隐藏导航栏时刷
- 20. 如何使用Jquery隐藏导航栏?
- 21. 与表视图隐藏导航栏
- 22. 在根视图中隐藏导航栏?
- 23. 的iOS NavigationController隐藏导航栏
- 24. 隐藏导航栏中的按钮
- 25. 隐藏和显示导航栏
- 26. 使用ROM隐藏导航栏Android 4.0+
- 27. C#UWP隐藏软导航栏
- 28. 导航栏中的SegmentedControll隐藏view.title
- 29. 隐藏导航栏时查看跳转
- 30. 如何在android中隐藏导航栏?
谢谢smallduck!伟大的阅读。 – 2011-03-11 23:20:13