iOS – Animation glitch with UIToolbar
===

I'm getting a "weird" animation glitch when I add a `UIToolbar` to the view. I'm animating the UIToolbar so it slides up from the bottom together with either a `UIPickerView` or a `UIDatePicker`. At first I see it's sliding up but after the animation is finished it quickly disappears. This happens when I slide down (animating the UIPickerView to slide down off the screen) and right after that I have another UIPickerView slide up. 

I noticed that if I set a delay (`- performSelector...`) on the slide up call for 0.3 seconds it will display the UIToolbar properly (anything less than 0.3 seconds will still have the same glitch). What might be causing this? This is the code I'm using:



    if ([self.view.subviews containsObject:self.dateRepeatPicker]) {
                    
            [self dismissDateRepeatPickerSegmentChanged:NO];
                    
             // "Hack", if I don't delay this call the UIToolbar will not display
             [self performSelector:@selector(showDatePicker) withObject:nil afterDelay:0.3];
                    
    } else if (![self.view.subviews containsObject:self.datePicker]) {
                    
             [self showDatePicker];
    }


    - (void)dismissDateRepeatPickerSegmentChanged:(BOOL)segmentChanged {
        
        CGRect toolbarTargetFrame = CGRectMake(0, self.view.bounds.size.height, 320, 44);
        CGRect dateRepeatPickerTargetFrame = CGRectMake(0, self.view.bounds.size.height+44, 320, 216);
        
        [UIView animateWithDuration:0.2 
         
                         animations:^{
                             self.pickerToolbar.frame = toolbarTargetFrame;
                             self.dateRepeatPicker.frame = dateRepeatPickerTargetFrame;
                         }
         
                         completion:^(BOOL finished) {
                             
                             if (segmentChanged) {
                                 
                                 [self.pickerToolbar removeFromSuperview];
                                 [self.dateRepeatPicker removeFromSuperview];
                                 [self.remindMeTableView reloadData];
                                 
                             } else {
                                 
                                 [self.pickerToolbar removeFromSuperview];
                                 [self.dateRepeatPicker removeFromSuperview];
                             }
                             
                         }];
    }

    - (void)showDatePicker {
        
    
        // Create the Toolbar over the Picker
        CGRect toolbarTargetFrame = CGRectMake(0, self.view.bounds.size.height-216-44, 320, 44);
        
        if (self.pickerToolbar == nil) {
            
            self.pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height, 320, 44)];
            self.pickerToolbar.barStyle = UIBarStyleBlack;
            self.pickerToolbar.translucent = YES;
        }
        
        UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
        UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"picker-dismiss.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(dismissDatePickerToolbar)];
        [self.pickerToolbar setItems:[NSArray arrayWithObjects:spacer, doneButton, nil]];
        [self.view addSubview:self.pickerToolbar];
        
        
        // Create the Picker under the Toolbar
        CGRect datePickerTargetFrame = CGRectMake(0, self.view.bounds.size.height-216, 320, 216);
        
        if (self.datePicker == nil) {
            
            self.datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height+44, 320, 216)];
            [self.datePicker setMinuteInterval:5];
            
            [self.datePicker addTarget:self action:@selector(changeDate:) forControlEvents:UIControlEventValueChanged];
            
        }
        
        [self.view addSubview:self.datePicker];
        
        [UIView animateWithDuration:0.2 animations:^{
            
            self.pickerToolbar.frame = toolbarTargetFrame;
            self.datePicker.frame = datePickerTargetFrame;
            
        }];
    }

