Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here's animation code, that I use:</p> <pre><code>- (void)animateDatePicker:(BOOL)show { CGRect screenRect = self.frame; CGSize pickerSize = [self.datePickerView sizeThatFits:CGSizeZero]; CGRect startRect = CGRectMake(0.0, screenRect.origin.y + screenRect.size.height, pickerSize.width, pickerSize.height); CGRect pickerRect = CGRectMake(0.0, screenRect.origin.y + screenRect.size.height - pickerSize.height, pickerSize.width, pickerSize.height); self.datePickerView.frame = pickerRect; self.backgroundColor = UIColorMakeRGBA( 64, 64, 64, 0.7f - (int)show * 0.7f ); if ( show ) { self.datePickerView.frame = startRect; [self.parentViewController addSubviewToWindow:self]; } [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.3f]; [UIView setAnimationDelegate:self]; self.backgroundColor = UIColorMakeRGBA( 64, 64, 64, 0.0f + (int)show * 0.7f ); if ( show ) { self.datePickerView.frame = pickerRect; } else { [UIView setAnimationDidStopSelector:@selector(slideDownDidStop)]; self.datePickerView.frame = startRect; } [UIView commitAnimations]; } </code></pre> <p>datePickerView is a view, that contains DatePicker:</p> <pre><code>self.datePickerView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 174.0, 320.0, 286.0)]; self.datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0.0, 70.0, 320.0, 216.0)]; [self.datePicker setDatePickerMode:UIDatePickerModeDate]; [self.datePicker addTarget:self action:@selector(pickerValueChanged:) forControlEvents:UIControlEventValueChanged]; [self.datePickerView addSubview:self.datePicker]; </code></pre> <p>parentViewController should implement addSubviewToWindow method:</p> <pre><code>- (void)addSubviewToWindow:(UIView *)addView { [self.view addSubview:addView]; } </code></pre> <p>UIColorMakeRGBA:</p> <pre><code>#define UIColorMakeRGBA(nRed, nGreen, nBlue, nAlpha) [UIColor colorWithRed:(nRed)/255.0f green:(nGreen)/255.0f blue:(nBlue)/255.0f alpha:nAlpha] </code></pre> <p>slideDownDidStop is a method, that will be called after datePicker slide down successfully.</p> <p>So, just to summarize - you have MyViewController, that have </p> <pre><code>MyDatePickerView *myDatePicker; </code></pre> <p>field.</p> <p>MyDatePickerView is a custom class, that have UIDatePicker *datePicker field, MyViewController *parentViewController and animateDatePicker method.</p> <p>When you perform some action on MyViewController (for example, UIControlEventTouchUpInside for some button), you should invoke </p> <pre><code>[myDatePicker animateDatePicker:YES]; </code></pre> <p>Please let me know if you have questions.</p> <p><strong>UPDATE:</strong> Here's a small <a href="http://89.112.8.39/so/DatePickerTest.zip" rel="nofollow noreferrer">example</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload