Reputation: 21
I am using a UIToolbar
in iOS and am trying to get a new button to 'arrive' by sliding in from the right. Is there a way to directly access the 'position' of the button on the bar? I currently have a messy workaround that is getting close to the desired effect, but i was hoping there was a way to move them using Core Animation, so i could implement the 'EaseInEaseOut' type timing functions. Any ideas?
- (void) testPart1 {
[NSTimer scheduledTimerWithTimeInterval:(0) target:self selector:@selector(testPart2:) userInfo:[NSNumber numberWithInt:500] repeats:NO];
}
- (void) testPart2:(NSTimer*)sender {
int countdown = [sender.userInfo integerValue];
theSpace.width = 10+(int)countdown;
itemTestButton.width = 49;
itemTestButton.width = 50;
countdown -= 5;
if(countdown>0)
[NSTimer scheduledTimerWithTimeInterval:(0.004) target:self selector:@selector(testPart2:) userInfo:[NSNumber numberWithInt:countdown] repeats:NO];
}
The premise here was using an NSTimer
to change the width of a Fixed Space Bar Button item, and count down to zero. I found I had to change the width of an actual button to make it work, otherwise no 'animation' would occur. It's messy I know, someone must have a cleaner way.
Upvotes: 2
Views: 261
Reputation: 7416
I would suggest adding a plain UIView
as a subview of the UIToolbar
that is rendered exactly as the bar button would be (you could get this by calling renderInContext:
on an existing button) and then animate that view into the proper position. In the completion block of that animation you could then set the real button and removeFromSuperview
the animation view, and it will look indistinguishable to the user.
Upvotes: 1