iOS 基本动画

1、改变frame

//开始做动画,关键字“move”-->移动动画

[UIView beginAnimations:@"move" context:nil];

//设置动画的持续时间

[UIView setAnimationDuration:2];

[UIView setAnimationDelegate:self];

[UIView setAnimationWillStartSelector:@selector(animationWillStartHandle)];

_myView.frame = CGRectMake(130, 300, 165, 100);

[UIView commitAnimations];

2、改变color

//开始做动画,关键字“color”-->改变颜色动画

[UIView beginAnimations:@"color" context:nil];

3、改变透明度

//开始做动画,关键字“alpha”-->改变透明度动画

[UIView beginAnimations:@"alpha" context:nil];

4、翻转

[UIView beginAnimations:@"doflip" context:nil];

[UIView setAnimationDuration:2];

[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:_myView cache:YES];

[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];

[UIView commitAnimations];

5、旋转

CGAffineTransform transform = CGAffineTransformRotate(_myView.transform, M_PI);

CGAffineTransform transform1 = CGAffineTransformMakeScale(0.5, 0.5);

[UIView beginAnimations:@"rotate" context:nil];

[UIView setAnimationDuration:2];

//-1:无限次

[UIView setAnimationRepeatCount:10];

_myView.transform = transform;

[UIView commitAnimations];

二、Spring

//Damping:0.0~1.0 阻尼系数,越小的话强度越大

//SpringVelocity:初速度

[UIView animateWithDuration:5 delay:0 usingSpringWithDamping:1 initialSpringVelocity:1 options:UIViewAnimationOptionRepeat animations:^{

_myImageView.backgroundColor = [UIColor grayColor];

} completion:^(BOOL finished) {

_myImageView.backgroundColor = [UIColor orangeColor];

NSLog(@"finish");

}];

三、block

1、

[UIView animateWithDuration:1 animations:^{

_myView.center = self.view.center;

}];

2、

//1、持续时间,2、要做的动画 3、动画完成之后的操作

[UIView animateWithDuration:3 animations:^{

_myView.center = self.view.center;

} completion:^(BOOL finished) {

NSLog(@"finish");

}];

3、

//block options包括了动画的很多选项

[UIView animateWithDuration:3 delay:2 options:UIViewAnimationOptionRepeat animations:^{

_myView.center = self.view.center;

} completion:^(BOOL finished) {

NSLog(@"finish");

}];

4、

//UIView用block去做关键帧动画

//在关键帧动画里边我们可以添加多个帧动画

//starttime:相对总时间的百分比的一个时间;3*0.5=1.5秒的时间开始走第二个帧动画

//每个帧动画持续的时间 =(Duration-StartTime)* 总时间

[UIView animateKeyframesWithDuration:3 delay:1 options:UIViewKeyframeAnimationOptionRepeat animations:^{

[UIView addKeyframeWithRelativeStartTime:0.0 relativeDuration:0.3 animations:^{

_myView.center = self.view.center;

_myView.backgroundColor = [UIColor grayColor];

}];

[UIView addKeyframeWithRelativeStartTime:0.3 relativeDuration:0.6 animations:^{

_myView.center = CGPointMake(200, 300);

_myView.backgroundColor = [UIColor orangeColor];

}];

[UIView addKeyframeWithRelativeStartTime:0.6 relativeDuration:1 animations:^{

_myView.center = CGPointMake(100, 400);

_myView.backgroundColor = [UIColor yellowColor];

}];

} completion:^(BOOL finished) {

NSLog(@"finishi");

}];

//动画效果

/*

UIViewAnimationOptionLayoutSubviews:动画过程中保证子视图跟随运动。

UIViewAnimationOptionAllowUserInteraction:动画过程中允许用户交互。

UIViewAnimationOptionBeginFromCurrentState:所有视图从当前状态开始运行。

UIViewAnimationOptionRepeat:重复运行动画。

UIViewAnimationOptionAutoreverse :动画运行到结束点后仍然以动画方式回到初始点。********

UIViewAnimationOptionOverrideInheritedDuration:忽略嵌套动画时间设置。

UIViewAnimationOptionOverrideInheritedCurve:忽略嵌套动画速度设置。

UIViewAnimationOptionAllowAnimatedContent:动画过程中重绘视图(注意仅仅适用于转场动画)。

UIViewAnimationOptionShowHideTransitionViews:视图切换时直接隐藏旧视图、显示新视图,而不是将旧视图从父视图移除(仅仅适用于转场动画)

UIViewAnimationOptionOverrideInheritedOptions :不继承父动画设置或动画类型。

2.动画速度控制(可从其中选择一个设置)

UIViewAnimationOptionCurveEaseInOut:动画先缓慢,然后逐渐加速。

UIViewAnimationOptionCurveEaseIn :动画逐渐变慢。

UIViewAnimationOptionCurveEaseOut:动画逐渐加速。

UIViewAnimationOptionCurveLinear :动画匀速执行,默认值。

3.转场类型(仅适用于转场动画设置,可以从中选择一个进行设置,基本动画、关键帧动画不需要设置)

UIViewAnimationOptionTransitionNone:没有转场动画效果。

UIViewAnimationOptionTransitionFlipFromLeft :从左侧翻转效果。

UIViewAnimationOptionTransitionFlipFromRight:从右侧翻转效果。

UIViewAnimationOptionTransitionCurlUp:向后翻页的动画过渡效果。

UIViewAnimationOptionTransitionCurlDown :向前翻页的动画过渡效果。

UIViewAnimationOptionTransitionCrossDissolve:旧视图溶解消失显示下一个新视图的效果。

UIViewAnimationOptionTransitionFlipFromTop :从上方翻转效果。

UIViewAnimationOptionTransitionFlipFromBottom:从底部翻转效果。

*/

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥ios动画全貌。在这里你可以看...
    每天刷两次牙阅读 8,572评论 6 30
  • 在iOS实际开发中常用的动画无非是以下四种:UIView动画,核心动画,帧动画,自定义转场动画。 1.UIView...
    请叫我周小帅阅读 3,159评论 1 23
  • 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥iOS动画全貌。在这里你可以看...
    F麦子阅读 5,141评论 5 13
  • 先看看CAAnimation动画的继承结构 CAAnimation{ CAPropertyAnimation { ...
    时间不会倒着走阅读 1,694评论 0 1
  • 前言 本文只要描述了iOS中的Core Animation(核心动画:隐式动画、显示动画)、贝塞尔曲线、UIVie...
    GitHubPorter阅读 3,661评论 7 11