一、UIView基础动画
1.动画的设置
(1).传统方式设置动画
// 动画开始
[UIView beginAnimations:@"textAnimations" context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelegate:self];
//UIViewAnimationCurveEaseInOut开始时和结束时慢 中间快
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
CGRect frame= self.myview.frame;
frame.origin.y += 400;
self.myview.frame = frame;
(2) .用block语法设置动画
[UIView animateWithDuration:0.5 animations:^{
CGRect frame= self.myview.frame;
frame.origin.y += 400;
self.myview.frame = frame;
}];
2.监听事件的结束
(1)block语法监听
self.myview.alpha = 1;
[UIView animateWithDuration:0.5 animations:^{
CGRect frame= self.myview.frame;
frame.origin.y += 400;
self.myview.frame = frame;
self.myview.alpha = 0;
//缩放变换
self.myview.transform = CGAffineTransformMakeScale(0.01, 0.01);
}completion:^(BOOL finished)
{
if(finished)
{
[UIView animateWithDuration:0.5 animations:^{
CGRect frame= self.myview.frame;
frame.origin.y -= 400;
self.myview.frame = frame;
self.myview.alpha = 1;
self.myview.transform = CGAffineTransformIdentity;
}];
}
}];
(2)设置代理监听
// 动画结束时调用 (传统方式监听动画结束)
[UIView setAnimationDidStopSelector:@selector(StopAnnimotion)];
[UIView commitAnimations];
二、视图切换动画
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
CGRect frame= self.myview.frame;
frame.origin.y -= 400;
self.myview.frame = frame;
[UIView commitAnimations];
三、自定义动画
CATransition *animation = [[CATransition alloc]init];
animation.type = kCATransitionReveal;
animation.subtype = kCATransitionFromTop;
animation.repeatCount = 20;
animation.timingFunction =[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut] ;
animation.duration = 0.5;
[self.myview.layer addAnimation:animation forKey:@"animationkey"];
[self.myview exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
[self.navigationController.view.layer addAnimation:animation forKey:@"key"];