Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 19, 2011, 11:24 AM   #1
darthtroll
macrumors newbie
 
Join Date: Aug 2010
UIBarButtonItem animations

This is what I have in my navigationItem: back button, UISearchBar (as the titleView) which is a part of my subclassed searchDisplayController, and map button in the rightBarItem slot.

WHAT WORKS:
When a user clicks into the UISearchBar, the back button and mapbutton animate away, the searchBar fills up the gap left by the back button disappearing, and the cancel button appears. This is working fine.
I've done this with the searchBarTextDidBeginEditing method:
Code:
self.navigationItem.hidesBackButton = YES;
self.navigationItem.rightBarButtonItem = nil;
WHAT DOESN'T:
However, I can't get the reverse animation just right, when the user leaves the searchBar. I'm allocating a new UIBarButtonItem and putting it into the navigationItem.rightBarButtonItem, and I'm setting self.navigationItem.hidesBackButton = NO in the searchBarTextDidEndEditing delegate method. What happens is that the buttons appear very sudden, the searchBar expands to the full width of the screen (which I want to prevent from happening), and then shrinks again to where it ought to be.

Does anybody have any suggestions to get the animations to behave well?

Darthtroll
darthtroll is offline   0 Reply With Quote
Old Jan 20, 2011, 12:12 AM   #2
darthtroll
Thread Starter
macrumors newbie
 
Join Date: Aug 2010
So there's been a bit of improvement. I tried [self.navigationItem.titleView sizeToFit] to see what sort of effect it might have, and now search bar plays nicely with the back button, but not the right button!

Here is my code:
Code:
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar {
	self.navigationItem.hidesBackButton = YES;
	self.navigationItem.rightBarButtonItem = nil;
}

- (void)searchBarTextDidEndEditing:(UISearch *)searchBar {
	self.navigationItem.hidesBackButton = NO;
	UIBarButtonItem *mapButton = [[UIBarButtonItem alloc] initWithTitle:@"Map" style: UIBarButtonItemStyleBordered target:self action:@selector(mapView:)];
	self.navigationItem.rightBarButtonItem = mapButton;
	[mapButton release];
	[self.navigationItem.titleView sizeToFit];
}
So to recap...

Starting State: searchBar takes up the left and middle, cancel button on the right
Transition State: back button takes up left, searchBar takes up the middle and right, mapButton takes up the right as well
End State: searchBar is in the middle

Any help would be greatly appreciated

Darthtroll
darthtroll is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
New Animations are SO MUCH BETTER [in 7.0.3] kre62 iOS 7 259 Oct 28, 2013 01:17 PM
Animations TrenttonY iOS 7 1 Jun 12, 2013 12:15 AM
UIBarButtonItem action jvpython iPhone/iPad Programming 4 Aug 18, 2012 10:52 PM
Stuttery Animations penguintri OS X 10.8 Mountain Lion 4 Jul 12, 2012 09:42 AM
displaying uibarbuttonitem for one of controllers connected to tab bar controller johnmerlino iPhone/iPad Programming 6 Jun 15, 2012 02:00 AM

Forum Jump

All times are GMT -5. The time now is 04:05 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC