#import <UIKit/UIKit.h> @interface ViewController : UIViewController @property (retain, nonatomic) IBOutlet UIDatePicker *pickerView; - (IBAction)popView:(id)sender; - (IBAction)inView:(id)sender; @property (nonatomic, retain) NSString *string; @end
- (void)viewDidLoad { [super viewDidLoad]; self.pickerView.frame = CGRectMake(0, 480, 320, 260); }把pickerView 放到屏幕以为下面。 4、弹出和弹回pickerView
- (IBAction)popView:(id)sender { CGContextRef context = UIGraphicsGetCurrentContext(); [UIView beginAnimations:nil context:context]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; [UIView setAnimationDuration:0.6];//动画时间长度,单位秒,浮点数 [self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1]; self.pickerView.frame = CGRectMake(0, 245, 320, 260); [UIView setAnimationDelegate:self]; // 动画完毕后调用animationFinished [UIView setAnimationDidStopSelector:@selector(animationFinished)]; [UIView commitAnimations]; } - (IBAction)inView:(id)sender { CGContextRef context = UIGraphicsGetCurrentContext(); [UIView beginAnimations:nil context:context]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; [UIView setAnimationDuration:0.6];//动画时间长度,单位秒,浮点数 self.pickerView.frame = CGRectMake(0, 480, 320, 260); [UIView setAnimationDelegate:self]; // 动画完毕后调用animationFinished [UIView setAnimationDidStopSelector:@selector(animationFinished)]; [UIView commitAnimations]; } -(void)animationFinished{ NSLog(@"动画结束!"); }动画结束后回调动画结束的函数。
- (void)ViewAnimation:(UIView*)view willHidden:(BOOL)hidden { [UIView animateWithDuration:0.3 animations:^{ if (hidden) { view.frame = CGRectMake(0, 480, 320, 260); } else { [view setHidden:hidden]; view.frame = CGRectMake(0, 245, 320, 260); } } completion:^(BOOL finished) { [view setHidden:hidden]; }]; }
- (IBAction)popView:(id)sender { [self ViewAnimation:self.pickerView willHidden:NO]; } - (IBAction)inView:(id)sender { [self ViewAnimation:self.pickerView willHidden:YES]; }这个方法更简单实用
著作权声明:本文由http://blog.csdn.net/totogo2010/原创,欢迎转载分享。请尊重作者劳动,转载时保留该声明和作者博客链接,谢谢