重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
这期内容当中小编将会给大家带来有关怎么在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中实现一个图片抖动效果了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注创新互联行业资讯频道。