iOS11 无法获取_titleView
Opened this issue · 7 comments
Deleted user commented
-
(void)lt_setTitleAlpha:(CGFloat)alpha {
if (@available(iOS 11.0, *)) {
} else {
UIView *titleView = [self valueForKey:@"_titleView"]; titleView.alpha = alpha;
}
}
MrWilsonXu commented
同样 [self valueForKey:@"_leftViews"] 会crash
KinmoCode commented
想问一下这个问题你们解决了吗?
KinmoCode commented
解决的话可以贴一下解决方式么
xq931014 commented
[self valueForKey:@"_leftViews"] 会crash的我的解决办法
会crash的原因是,iOS11 UINavigationBar 没有_leftViews,_rightViews,_titleView这些key
解决办法:通过代码找到leftButton 、rightButton和titleView,然后改变他们的透明度
tip:我们项目中没有用到titleView,所以我找到了leftButton和rightButton,至于titleView在哪,需要自己慢慢去发现
//如果是iOS 11
if (@available(iOS 11, *))
{
[[self subviews] enumerateObjectsUsingBlock:^(UIView *obj, NSUInteger idx, BOOL *stop) {
if ([obj isKindOfClass:NSClassFromString(@"_UINavigationBarContentView")]) {
for (UIView *view in [obj subviews])
{
view.alpha = alpha;
}
}
}];
}
else
{
[[self valueForKey:@"_leftViews"] enumerateObjectsUsingBlock:^(UIView *view, NSUInteger i, BOOL *stop) {
view.alpha = alpha;
}];
[[self valueForKey:@"_rightViews"] enumerateObjectsUsingBlock:^(UIView *view, NSUInteger i, BOOL *stop) {
view.alpha = alpha;
}];
UIView *titleView = [self valueForKey:@"_titleView"];
titleView.alpha = alpha;
}
KinmoCode commented
emmm,因为这个第三方很久没维护了,所以我用了另外一个:https://github.com/wangrui460/WRNavigationBar,不过个人使用后感觉侵入性还是有点强,你可以参考一下