美文网首页
iOS 基本动画

iOS 基本动画

作者: Lambo316 | 来源:发表于2016-06-28 09:55 被阅读96次

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动画之UIView动画

    iOS动画 UIView动画 UIViewAnimationOptions参考 1. 基本动画 + (void)a...

  • iOS Animation创建及使用

    iOS 实现的基本动画 头尾式动画 2.block动画的方法 iOS显示关键帧动画 关键帧动画 动画的创建和使用 ...

  • UIView二维动画与CAAnimation核心动画

    1 iOS动画 iOS的动画基本分为以下三种: 仿射形变动画(基于UIView) 核心动画(CAAnimation...

  • iOS基础 - 核心动画(转)

    iOS基础 - 核心动画 一、核心动画 l核心动画基本概念 l基本动画 l关键帧动画 l动画组 l转场动画 lCo...

  • iOS 基本动画

    1、改变frame //开始做动画,关键字“move”-->移动动画 [UIView beginAnimation...

  • iOS 基本动画

    # CoreAnimation Core Animation,中文翻译为核心动画,它是一组非常强大的动画处理API...

  • ios 动画总结(未完)

    针对iOS 动画做一下总结 基本动画 帧动画 组动画 转场动画 !- - !插一句UIview代码块(能实现最简...

  • ios动画

    ios动画 ios动画2 ios动画3

  • iOS 动画篇 - pop动画库

    Pop 是 iOS,tvOS 和 OS X 的可扩展动画引擎。除了基本的静态动画外,他支持弹性和衰减动画动态动画,...

  • iOS动画

    iOS动画-从UIView动画说起iOS动画-Transform和KeyFrame动画iOS动画-layout动画...

网友评论

      本文标题:iOS 基本动画

      本文链接:https://www.haomeiwen.com/subject/rfktjttx.html