Tip-控件抖动提示动画。

155 阅读1分钟
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface CTAnimation : NSObject

//视图抖动动画

+ (void)shakeAnimationForView:(UIView *) view;
@end


#import "CTAnimation.h"

@implementation** CTAnimation
+ (**void**)shakeAnimationForView:(UIView *) view {

    CALayer *viewLayer = view.layer;

    CGPoint position = viewLayer.position;

    CGPoint right = CGPointMake(position.x + 10, position.y);

    CGPoint left = CGPointMake(position.x - 10, position.y);

    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];

    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

    [animation setFromValue:[NSValue valueWithCGPoint:right]];

    [animation setToValue:[NSValue valueWithCGPoint:left]];

    [animation setAutoreverses:YES];

    [animation setDuration:.06];

    [animation setRepeatCount:3];

    [viewLayer addAnimation:animation forKey:**nil**];

}

@end

  • 这是一个简单的抖动动画用于提示用户注意那个控件的问题。
  • 主要使用的技术原理就是获取控件的layer层,然后做控件的左右两侧加10的坐标点。然后在这两个坐标点之间做一个基础的平移动画。
  • 这个是看到的一个比较有趣的东西简单记录一下