Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Animation Desk for iPhone - Anyone can be an animator. Any idea matters. (New Video) swopes iPhone and iPod touch Apps 4 Jul 24, 2011 09:59 AM
zoom animation using animation with block based methods ashwinr87 iPhone/iPad Programming 4 Apr 20, 2011 09:24 AM
Enabling an uibarbuttonitem when at least one char is written in a uitextfield franium iPhone/iPad Programming 5 Feb 25, 2011 12:09 PM
How does one make a UIImage Animation stop on an image. nickculbertson iPhone/iPad Programming 3 Nov 20, 2010 07:50 AM
How to write a jQuery animate in this situation? youlichika Web Design and Development 1 Nov 19, 2010 03:47 PM


All times are GMT -5. The time now is 09:50 AM.

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

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