7

I've been experiencing some troubles with animating the alpha of certaing subviews of my Navigation Bar. Here is the initial state of the bar:

enter image description here

Here is how far did I get by now:

enter image description here

The thing is that I need to make all this "star", "new" and other round buttons transparent when the search is active (I need to reduce their alpha to zero). I am trying to make them transparent in the following methods of the delegate:

- (void)searchBarCancelButtonClicked:(UISearchBar *)asearchBar
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar

In all of them I do quite the same code:

//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
  }
}

However, I couldn't achieve the desired result this way, though I am getting right alpha values at that NSLog, buttons don't fade at all. Are there any suggestions on what can I possibly be doing wrong?

EDIT 1:

I think I should add some description of the view hierarchy in my case. Well, I have the UISegmentedConrol, which holds these round buttons and also two UIImageViews, the background for segmented control, and the triangle pointer. All of these views are added to the navigation bar as it's subviews. Also there is a rectangular view, which holds the searchbar, and is also added as a subview to the navigation bar later, so it's the top view in the hierarchy. Also, I am animating my searchBar by simply animating the frame of its superview (expanding or condensing it, when the events above occur in the delegate). I hope I've given all the necessary information.

morgan1189
  • 279
  • 1
  • 10
  • u only want button or also UISearch Bar too ??? – iPatel Mar 26 '13 at 19:30
  • Just use a custom UITextField that overlays the whole scene. – ott-- Mar 26 '13 at 19:36
  • I want buttons to be active when search bar is not active, and i want buttons to be not visible when search bar is active. – morgan1189 Mar 26 '13 at 19:40
  • ott, excuse me, but could you be more specific please? I just didn't get how that can help me. – morgan1189 Mar 26 '13 at 19:41
  • 1
    Have you tried setting hidden = YES? If not, they may end up still touching the views. Is this a UINavigationBar? Please describe the views. – Marcus Adams Mar 26 '13 at 21:20
  • Thanks for your response, Marcus. I've edited my post to describe the views. I guess hidden is not alright for me, because I need to animate their fading. Or is it OK? – morgan1189 Mar 28 '13 at 08:34

2 Answers2

1

Its been a while since I did ios programming. It is possible that even though you are setting the alpha, but not triggering a repaint. [UIView setNeedsDisplay] might help to refresh the drawing in the next drawing cycle.

For a reference: What is the most robust way to force a UIView to redraw?

Community
  • 1
  • 1
ssinganamalla
  • 1,250
  • 3
  • 12
  • 19
1

1) This is UI update problem,write this statement after any UI update code.

 [[NSRunLoop currentRunLoop] runUntilDate:[NSDate date]];

this will update your GUI.

or

2) use perform selector on main thread and update your UI in selector method.

 [self performSelectorOnMainThread:@selector(UpdateUIMethod) withObject:self waitUntilDone:NO];
Vin
  • 10,517
  • 10
  • 58
  • 71
Akshay
  • 11
  • 1