// 基础动画
- (void)moveView:(UIButton *)btn
{
NSLog(@"%s",__FUNCTION__);
// 开始 名字随便取
[UIView beginAnimations:@"aaa" context:nil];
// 动画类型
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
// 时长
[UIView setAnimationDuration:1.0];
// 代理
[UIView setAnimationDelegate:self];
// default = NULL. -animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
// animationID对应上面的@"aaa"
//[UIView setAnimationDidStopSelector:@selector(stopAnim)];
/* 动画的处理写在这里 */
// 改变上下视图的动画1、动画类型 2、两个视图的父视图 3、yes
/*
UIViewAnimationTransitionNone,
UIViewAnimationTransitionFlipFromLeft,
UIViewAnimationTransitionFlipFromRight,
UIViewAnimationTransitionCurlUp, // 翻页效果
UIViewAnimationTransitionCurlDown, //
*/
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
// 在父视图调换两个视图层级
// NSInteger index = [self.view.subviews indexOfObject:animView];
[self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
// 提交动画
[UIView commitAnimations];
/* block实现动画 */
[UIView animateWithDuration:0.5 animations:^{
// 动画内容
} completion:^(BOOL finished) {
// 动画结束处理
}];
}
// 缩放动画
- (void)scaleAnim
{
// 初始值
CGAffineTransform Transform = animView.transform;
// 缩放比例
animView.transform = CGAffineTransformScale(Transform, 1, 1);
[UIView animateWithDuration:0.5 animations:^{
// 缩放到0.01,改值不能为零
animView.transform = CGAffineTransformScale(animView.transform, 0.01, 0.01);
} completion:^(BOOL finished) {
// 恢复为原始状态
animView.transform = CGAffineTransformIdentity;
}];
}
// 核心动画
- (void)coreAnim
{
CATransition *anim = [CATransition animation];
anim.duration = 0.6;
// 加速、减速等 `linear', `easeIn', `easeOut' and`easeInEaseOut' and `default'
anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
// 淡入、push等
anim.type = kCATransitionReveal;
// type的子类型/ 上下左右等
anim.subtype = kCATransitionFromLeft;
// 名字随便
[self.view.layer addAnimation:anim forKey:@"abc"];
[self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
}
// 改变导航控制器push动画
- (void)customNavAnim
{
CATransition *transition = [CATransition animation];
transition.duration = 0.7;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromLeft;
// 动画加在layer上
[self.navigationController.view.layer addAnimation:transition forKey:@"ccc"];
// 推出下一视图即可
UIViewController *vc = [[UIViewController alloc] init];
// 不显示系统动画 NO
[self.navigationController pushViewController:vc animated:NO];
}