您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
这期内容当中小编将会给大家带来有关怎么在iOS中实现一个图片抖动效果,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
#import "ViewController.h" #define angle2Rad(angle) ((angle) / 180.0 *M_PI) @interface ViewController () @property (weak, nonatomic) IBOutlet UIImageView *imageV; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.imageV.userInteractionEnabled = YES; //添加长按手势 UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)]; [self.imageV addGestureRecognizer:longPress]; } - (void)longPress:(UILongPressGestureRecognizer *)longPress{ //创建动画对象 CAKeyframeAnimation *anim = [CAKeyframeAnimation animation]; anim.keyPath = @"transform.rotation"; anim.values = @[@(angle2Rad(-5)),@(angle2Rad(5))]; anim.repeatCount = MAXFLOAT; // anim.duration = 1; anim.autoreverses = YES; [self.imageV.layer addAnimation:anim forKey:nil]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
小编再给大家补充一段iOS UIView视图抖动效果的实现代码:
/** * 抖动效果 * * @param view 要抖动的view */ - (void)shakeAnimationForView:(UIView *) view { CALayer *viewLayer = view.layer; CGPoint position = viewLayer.position; CGPoint x = CGPointMake(position.x + 1, position.y); CGPoint y = CGPointMake(position.x - 1, position.y); CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"]; [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]]; [animation setFromValue:[NSValue valueWithCGPoint:x]]; [animation setToValue:[NSValue valueWithCGPoint:y]]; [animation setAutoreverses:YES]; [animation setDuration:.06]; [animation setRepeatCount:3]; [viewLayer addAnimation:animation forKey:nil]; }
上述就是小编为大家分享的怎么在iOS中实现一个图片抖动效果了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注亿速云行业资讯频道。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。