美文网首页移动端技术
UIView的动画块代码

UIView的动画块代码

作者: jump宫本 | 来源:发表于2018-08-31 17:20 被阅读3次

block 的方法主要有 7 个

这个是用的最多的 ( 主要在于参数的和回调)

+ (void)animateWithDuration:(NSTimeInterval)duration                      delay:(NSTimeInterval)delay                    options:(UIViewAnimationOptions)options                  animations:(void(^)(void))animations                  completion:(void(^ __nullable)(BOOLfinished))completion ;[UIViewanimateWithDuration:(NSTimeInterval)// 动画的持续时间delay:(NSTimeInterval)// 动画执行的延迟时间options:(UIViewAnimationOptions)// 执行的动画选项,animations:^{// 要执行的动画代码} completion:^(BOOLfinished) {// 动画执行完毕后的调用}];

和上一个方法相比较,少了动画延迟和动画选项 (使用的复杂度比上一个小)

+ (void)animateWithDuration:(NSTimeInterval)duration                animations:(void(^)(void))animations                completion:(void(^ __nullable)(BOOLfinished))completionNS_AVAILABLE_IOS(4_0);// delay = 0.0, options = 0[UIViewanimateWithDuration:(NSTimeInterval)                  animations:^{// 要执行的动画代码} completion:^(BOOLfinished) {// 动画执行完毕后的调用}];

这个是最简单的,对动画的设置基本没有,使用的都是默认参数

+ (void)animateWithDuration:(NSTimeInterval)duration                animations:(void(^)(void))animationsNS_AVAILABLE_IOS(4_0);// delay = 0.0, options = 0, completion = NULL[UIViewanimateWithDuration:(NSTimeInterval) animations:^{            }];

Spring Animationring Animation

在IOS7开始,系统动画效果广泛应用Spring Animation

+ (void)animateWithDuration:(NSTimeInterval)duration                      delay:(NSTimeInterval)delay    usingSpringWithDamping:(CGFloat)dampingRatio      initialSpringVelocity:(CGFloat)velocity                    options:(UIViewAnimationOptions)options                animations:(void(^)(void))animations                completion:(void(^ __nullable)(BOOLfinished))completionNS_AVAILABLE_IOS(7_0);    [UIViewanimateWithDuration:(NSTimeInterval)// 动画持续时间delay:(NSTimeInterval)// 动画延迟时间usingSpringWithDamping:(CGFloat)// 类似弹簧振动效果 0~1initialSpringVelocity:(CGFloat)// 初始速度options:(UIViewAnimationOptions)// 动画过渡效果animations:^{// code} completion:^(BOOLfinished) {// code}]usingSpringWithDamping:它的范围为0.0f 到1.0f ,数值越小「弹簧」的振动效果越明显。initialSpringVelocity:初始的速度,数值越大一开始移动越快。值得注意的是,初始速度取值较高而时间较短时,也会出现反弹情况。Spring Animation 是线性动画或 ease-out动画的理想替代品。由于 iOS 本身大量使用的就是 Spring Animation,用户已经习惯了这种动画效果,因此使用它能使 App 让人感觉更加自然,用 Apple 的话说就是「instantly familiar」。此外,Spring Animation 不只能对位置使用,它适用于所有可被添加动画效果的属性。

+ (void)transitionWithView:(UIView*)view                      duration:(NSTimeInterval)duration                        options:(UIViewAnimationOptions)options                    animations:(void(^ __nullable)(void))animations                    completion:(void(^ __nullable)(BOOLfinished))completionNS_AVAILABLE_IOS(4_0);            [UIViewtransitionWithView:(nonnullUIView*)                      duration:(NSTimeInterval)                      options:(UIViewAnimationOptions)options                    animations:^{        code    } completion:^(BOOLfinished) {        code    }];

+ (void)transitionFromView:(UIView*)fromView                    toView:(UIView*)toView                  duration:(NSTimeInterval)duration                    options:(UIViewAnimationOptions)options                completion:(void(^ __nullable)(BOOLfinished))completionNS_AVAILABLE_IOS(4_0);// toView added to fromView.superview, fromView removed from its superview[UIViewtransitionFromView:(nonnullUIView*)                    toView:(nonnullUIView*)                  duration:(NSTimeInterval)                  options:(UIViewAnimationOptions)                completion:^(BOOLfinished) {                        code  }];

+ (void)performSystemAnimation:(UISystemAnimation)animation                    onViews:(NSArray<__kindofUIView*> *)views                    options:(UIViewAnimationOptions)options animations:(void(^ __nullable)(void))parallelAnimations                completion:(void(^ __nullable)(BOOLfinished))completionNS_AVAILABLE_IOS(7_0);[UIViewperformSystemAnimation:<(UISystemAnimation)>                      onViews:(nonnullNSArray<__kindofUIView*> *)                      options:<(UIViewAnimationOptions)>                    animations:^{    code} completion:^(BOOLfinished) {    code}]

三、关键帧动画

关键帧动画

iOS 8 Spring Animation

UIView动画已经具备高级的方法来创建动画,而且可以更好地理解和构建动画。

IOS7以后苹果新加了一个animateKeyframesWithDuration的方法,我们可以使用它来创建更多更复杂更酷炫的动画效果,而不需要去使用到核心动画(CoreAnimatino)。

/** * 添加关键帧方法 * *@paramduration 动画时长 *@paramdelay 动画延迟 *@paramoptions 动画效果选项 *@paramanimations 动画执行代码 *@paramcompletion 动画结束执行代码 */+ (void)animateKeyframesWithDuration:(NSTimeInterval)duration                                delay:(NSTimeInterval)delay                              options:(UIViewKeyframeAnimationOptions)options                          animations:(void(^)(void))animations                          completion:(void(^)(BOOL finished))completion;

相关文章

  • UIView的动画块代码

    block 的方法主要有 7 个 这个是用的最多的 ( 主要在于参数的和回调) + (void)animateWi...

  • ios 动画总结(未完)

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

  • iOS--UIView动画

    一、UIView动画 1、基础动画 //标记动画块开始 [UIView beginAnimations:nil c...

  • iOS 核心动画 Core Animation浅谈

    前记 关于实现一个iOS动画,如果简单的,我们可以直接调用UIView的代码块来实现,虽然使用UIView封装的方...

  • IOS动画技术详解

    视图动画 UIView动画块 ios4.0之后在UIView类中提供以下几个处理动画的方法。 其中animateW...

  • iOS 核心动画的一些总结

    iOS动画的调用方式 第一种:UIView 代码块调用,可以参考http://www.jianshu.com/p/...

  • iOS动画(三)----CoreAnimation(核心动画)原

    UIView动画一个代码块能实现一个动画,实现一些常规简单动画比较快捷省心。当面对特殊的产品需求,如动画的停止启动...

  • ios UIView动画

    UIView简单的frame改变动画,代码如下:

  • iOS动画总结01

    iOS 动画:1.试图动画 :UIview动画(动画块、过渡动画) 2.核心动画Core Ani...

  • UI阶段第二天

    一脸懵逼的我。 UIView父子视图 还是通过代码来理解吧: 视图的层次关系 代码示例: UIView动画 代码示...

网友评论

    本文标题:UIView的动画块代码

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