Search code examples
iosanimationuitoolbaruidatepicker

Setting an animation for a toolbar from the beginning


I have a textfield which has a UIDatePicker instead of a keyboard. I also made a toolbar not connected with the datePicker but that just appears when the textfield is tapped. The problem is the animations. The datePicker slides up nicely, but the toolbar just appears before the animation of the datePicker is done. This makes the whole thing look horrible. How would I set the animation to match the datePickers? I have no experience with animations and none of the other posts did any good for me.


EDIT

Based on Tareks answer I was able to set the animation to slide up by doing the following.

First, Setting the toolbar to bottom of screen

pickerBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 480, 320, 44)];

Seconds, Changing the location of the toolbar in the animation

[UIView animateWithDuration:.4 animations:^(void) {

    CGRect rect = CGRectMake(0, 224-46, 320, 44);

    [pickerBar setFrame:rect];

Solution

  • You can use code below to show your toolBar:

    [UIView animateWithDuration:2.0 animations:^(void) {
        toolBar.alpha = 1;
    }];
    

    EDIT:

    toolBar.alpha should be 0.

    For Sliding: It is gonna something like:

    [UIView animateWithDuration:2 animations:^{
         int newY = yVal; // you can play with this newY.
         CGRect frame = toolBar.frame;
         frame.origin.y = newY;
         toolBar.frame  = frame;
    }];