[plain]
- (IBAction)doneAction:(id)sender { CGRect screenRect = [[UIScreen mainScreen] applicationFrame]; CGRect endFrame = self.pickerView.frame; endFrame.origin.y = screenRect.origin.y + screenRect.size.height; // start the slide down animation [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.3]; // we need to perform some post operations after the animation is complete [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(slideDownDidStop)]; self.pickerView.frame = endFrame; [UIView commitAnimations]; // grow the table back again in vertical size to make room for the date picker CGRect newFrame = self.tableView.frame; newFrame.size.height += self.pickerView.frame.size.height; self.tableView.frame = newFrame; // remove the "Done" button in the nav bar self.navigationItem.rightBarButtonItem = nil; // deselect the current table row NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; } 3.从父视图移除
[plain]
- (void)slideDownDidStop { // the date picker has finished sliding downwards, so remove it [self.pickerView removeFromSuperview]; } 参考代码DateCell