我一直在为我的导航栏的主要子视图的动画制作动画遇到一些麻烦.这是条形的初始状态:

这是我现在走了多远:

问题是,当搜索处于活动状态时,我需要使所有这些"星形","新"和其他圆形按钮透明(我需要将它们的alpha降低到零).我试图在委托的以下方法中使它们透明:
- (void)searchBarCancelButtonClicked:(UISearchBar *)asearchBar
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
Run Code Online (Sandbox Code Playgroud)
在所有这些中我做了完全相同的代码:
//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
}
}
Run Code Online (Sandbox Code Playgroud)
但是,我无法通过这种方式获得所需的结果,虽然我在NSLog上获得了正确的alpha值,但按钮根本不会消失.我有什么可能做错的建议吗?
编辑1:
我想我应该在我的案例中添加一些视图层次结构的描述.好吧,我有UISegmentedConrol,它包含这些圆形按钮和两个UIImageViews,分段控制的背景和三角形指针.所有这些视图都会作为子视图添加到导航栏中.还有一个矩形视图,它包含搜索栏,稍后也会作为子视图添加到导航栏,因此它是层次结构中的顶视图.此外,我通过简单地设置其superview框架的动画来动画我的searchBar(扩展或缩小它,当上面的事件发生在委托中时).我希望我已经提供了所有必要的信息.
根据该文件为-[UIView setNeedsLayout]:
由于此方法不强制立即更新,而是等待下一个更新周期,因此可以在更新任何视图之前使用它来使多个视图的布局无效.此行为允许您将所有布局更新合并到一个更新周期,这通常会提高性能.
听起来很棒 - 但是当我在setNeedsLayout没有打电话的情况下使用时layoutIfNeeded,我发现我的控制并没有自行解决.我曾希望在下次显示控件之前会发生"更新周期",但我想这不是它的工作原理.那么什么是"更新周期"?什么时候发生?
我正在为我正在制作的纸牌游戏添加一些基本动画.(我的第一个iPhone应用程序.)
我正在创建一个自定义的UIView类"AnimationContainer",它从image1翻转到image2,同时从rect1移动到rect2.我的最终目的是让这些容器中最多有四个同时进行转换.
我遇到的问题是动画没有显示image1 ...因此只显示翻转过渡的后半部分.
但是,如果我首先通过触摸重置重置动画,那么一切都很完美.换句话说,如果我反复按Flip,我只能获得一半的转换......但是如果我先按下Reset,那么一切都可以完美地完成一次翻转.
那么,我怎样才能使动画正确重置?
下面是代码,截图,这里是完整的链接:Project Zip File 700k.
alt text http://www.robsteward.com/cardflip.jpg
- (void)displayWithImage1 { //RESET button calls this
self.frame = rect1;
[image2 removeFromSuperview];
[self addSubview:image1];
[self setNeedsDisplay]; //no help: doesn't force an update before animation
}
- (void)runTheAnimation { //FLIP button calls this
[self displayWithImage1]; //<---this is what the reset button calls
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:transition forView:self cache:NO];
self.frame = rect2;
[image1 removeFromSuperview];
[self addSubview:image2];
[UIView commitAnimations];
}
Run Code Online (Sandbox Code Playgroud)
谢谢!