UIview基础动画
- 格式:rtf
- 大小:5.97 KB
- 文档页数:2
- (void)viewDidLoad {
[super viewDidLoad];
NSString * fileDir = [[NSBundle mainBundle] pathForResource:@"别抢这是我的"
ofType:@"jpg"];
UIImage *img = [UIImage imageNamed:fileDir];
UIImageView *imgview = [[UIImageView alloc]initWithImage:img];
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.frame.origin.y+300,
self.view.bounds.size.width, 200)];
view.tag = 100;
view.backgroundColor = [UIColor orangeColor];
[view addSubview:imgview];
[self.view addSubview:view];
UIButton *butt = [UIButton buttonWithType:UIButtonTypeContactAdd];
butt.frame = CGRectMake(100, self.view.frame.origin.y+550, 200, 44);
[butt setTitle:@" 吹气球动画" forState:UIControlStateNormal];
[butt addTarget:self action:@selector(clickbutt:)
forControlEvents:UIControlEventTouchUpInside];
butt.backgroundColor = [UIColor purpleColor];
[self.view addSubview:butt];
// butt = [UIButton buttonWithType:UIButtonTypeContactAdd];
// butt.frame = CGRectMake(100, 50, 200, 44);
// [butt setTitle:@" 动画" forState:UIControlStateNormal];
// [butt addTarget:self action:@selector(clickbutt2:)
forControlEvents:UIControlEventTouchUpInside];
// butt.backgroundColor = [UIColor purpleColor];
// [self.view addSubview:butt];
// Do any additional setup after loading the view, typically from a nib.
}
-(void)clickbutt:(UIButton *)butt{
//-----------------传统方式的动画----------------
// [UIView beginAnimations:@"testAnimation" context:nil];
// [UIView setAnimationDelay:0.5];
// //动画方式,前加速后减速
//// [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
// UIView *view = [self.view viewWithTag:100];
// CGRect fram = view.frame;
// fram.origin.y =self.view.bounds.size.height*0.5;
//
// view.frame = fram;
// //动画结束
// [UIView commitAnimations];
//动画结束执行的方法
//[UIView setAnimationDidStopSelector:@selector(animOver)];
//--------------black方式的动画--------------------
[UIView animateWithDuration:0.5 animations:^{
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
UIView *view = [self.view viewWithTag:100];
CGRect fram = view.frame;
fram.origin.y =fram.origin.y -100;
view.frame = fram;
//改变透明度
view.alpha = 0;
//缩放
view.transform = CGAffineTransformScale(view.transform, 0.1, 0.1);
} completion:^(BOOL finished) {
if (finished) {
//动画结束后嵌入一个返回动画.
[UIView animateWithDuration:0.5 animations:^{
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
UIView *view = [self.view viewWithTag:100];
CGRect fram = view.frame;
fram.origin.y =fram.origin.y +100;
view.frame = fram;
//透明度
view.alpha = 1;
//缩放
//view.transform = CGAffineTransformScale(view.transform, 10, 10);
//恢复成原始的状态
view.transform = CGAffineTransformIdentity;
}];
}
}];
}