iOS - 如何使导航栏的子视图透明?
我一直在使用我的导航栏的动画确定子视图的alpha值时遇到一些麻烦。这里是酒吧的初始状态:iOS - 如何使导航栏的子视图透明?
这里多远我才拿到现在:
的事情是,我需要做这一切的“明星” ,“新”和其他圆形按钮透明时,搜索是积极的(我需要减少他们的α为零)。我试图让他们在委托的下列方法透明:
- (void)searchBarCancelButtonClicked:(UISearchBar *)asearchBar
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
在所有这些我做了很多相同的代码:
//parent is just a pointer of a search delegate, which points to view controller
for (UIView * someViewToFade in parent.navigationController.navigationBar.subviews) {
if (someViewToFade.tag == 88 || someViewToFade.tag == 11) {
NSLog("someViewToFade.alpha before changes = %f", someViewToFade.alpha);
someViewToFade.alpha = 0.0; //or 1.0, depending on the method
}
}
但是,我不能达到预期的效果这样,尽管我在该NSLog中获得了正确的alpha值,但按钮并没有完全消失。有什么我可能做错的建议吗?
编辑1:
我想我应该在我的情况下添加视图层次的一些描述。那么,我有UISegmentedConrol,它拥有这些圆形按钮,还有两个UIImageViews,分段控制的背景和三角形指针。所有这些视图都会作为子视图添加到导航栏中。此外还有一个矩形视图,它包含搜索栏,并且稍后还将其作为子视图添加到导航栏中,因此它是层次结构中的顶层视图。另外,我只是通过动画制作其超级视图的框架(扩展或缩小它,当以上事件发生在代表中时)来动画化我的搜索栏。我希望我已经提供了所有必要的信息。
自从我做了ios编程以来,它已经有一段时间了。即使您正在设置alpha,但不会触发重绘,这也是可能的。 [UIView setNeedsDisplay]可能有助于在下一个绘图周期中刷新绘图。
对于一个参考:What is the most robust way to force a UIView to redraw?
很抱歉这么说,但没有奏效。 – morgan1189 2013-03-26 19:45:19
设置alpha后,视图不必重新绘制。 – Sulthan 2013-03-26 19:55:12
好吧,很高兴知道。 – ssinganamalla 2013-03-26 22:48:50
1)这是UI更新的问题,写后的任何UI更新代码这一说法。
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate date]];
这将更新您的GUI。
或
2)使用上主线程执行选择和更新选择器方法的UI。
[self performSelectorOnMainThread:@selector(UpdateUIMethod) withObject:self waitUntilDone:NO];
你只想要按钮还是UISearch Bar呢? – iPatel 2013-03-26 19:30:44
只需使用覆盖整个场景的自定义UITextField。 – 2013-03-26 19:36:29
我希望按钮在搜索栏未激活时处于活动状态,并且当搜索栏处于活动状态时,我希望按钮不可见。 – morgan1189 2013-03-26 19:40:22