时间:2021-05-20
本文实例为大家分享了iOS实现图片抖动效果的具体代码,供大家参考,具体内容如下
效果图:
核心代码:
//// ViewController.m// 图标抖动//// Created by llkj on 2017/8/29.// Copyright © 2017年 LayneCheung. All rights reserved.//#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];}以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
本文实例讲述了js实现鼠标触发图片抖动效果的方法。分享给大家供大家参考。具体实现方法如下:复制代码代码如下:鼠标触发图片抖动效果.shakeimage{posi
上篇文章给大家介绍了JS实现简单抖动效果,感兴趣的朋友点击查看。今天给大家分享JS相册图片抖动放大展示效果,效果图如下所示:varxm;varym;/*====
本文实例为大家分享了ios字体抖动的具体实现代码,供大家参考,具体内容如下一、效果图二、代码viewcontroller.m?12345678910111213
本文实例讲解了基于javascript实现窗口抖动效果的详细代码,分享给大家供大家参考,具体内容如下效果图:鼠标点击,窗口实现抖动。具体代码:窗口登陆效果#wi
本文实例讲述了jQuery实现网页抖动的菜单抖动效果。分享给大家供大家参考。具体如下:这里的jQuery抖动导航菜单效果,兼容IE7/8/9及其它主流浏览器,使