iOS實(shí)現(xiàn)圖片抖動(dòng)效果
本文實(shí)例為大家分享了iOS實(shí)現(xiàn)圖片抖動(dòng)效果的具體代碼,供大家參考,具體內(nèi)容如下
效果圖:
核心代碼:
// // ViewController.m // 圖標(biāo)抖動(dòng) // // 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; //添加長按手勢(shì) UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)]; [self.imageV addGestureRecognizer:longPress]; } - (void)longPress:(UILongPressGestureRecognizer *)longPress{ //創(chuàng)建動(dòng)畫對(duì)象 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
小編再給大家補(bǔ)充一段iOS UIView視圖抖動(dòng)效果的實(shí)現(xiàn)代碼:
/** * 抖動(dòng)效果 * * @param view 要抖動(dòng)的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]; }
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- iOS實(shí)現(xiàn)支付寶螞蟻森林隨機(jī)按鈕及抖動(dòng)效果
- 詳解iOS中position:fixed吸底時(shí)的滑動(dòng)出現(xiàn)抖動(dòng)的解決方案
- iOS動(dòng)畫-定時(shí)對(duì)UIView進(jìn)行翻轉(zhuǎn)和抖動(dòng)的方法
- iOS實(shí)現(xiàn)自定義購物車角標(biāo)顯示購物數(shù)量(添加商品時(shí)角標(biāo)抖動(dòng) Vie)
- iOS字體抖動(dòng)動(dòng)畫的實(shí)現(xiàn)代碼
- IOS倒計(jì)時(shí)設(shè)置UIButton標(biāo)題title的抖動(dòng)問題
- iOS自定義button抖動(dòng)效果并實(shí)現(xiàn)右上角刪除按鈕
- 仿iOS圖標(biāo)抖動(dòng)
相關(guān)文章
iOS利用AFNetworking3.0——實(shí)現(xiàn)文件斷點(diǎn)下載
這篇文章主要介紹了iOS利用AFNetworking3.0——實(shí)現(xiàn)文件斷點(diǎn)下載,具有一定的參考價(jià)值,有興趣的可以了解一下。2017-01-01iOS bounds學(xué)習(xí)筆記以及仿寫UIScrollView部分功能詳解
這篇文章主要為大家詳細(xì)介紹了iOS bounds學(xué)習(xí)筆記,以及仿寫UIScrollView部分功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-05-05ios實(shí)現(xiàn)tableView頂部彈簧圖片效果
這篇文章主要為大家詳細(xì)介紹了ios實(shí)現(xiàn)tableView頂部彈簧圖片效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-08-08實(shí)例講解iOS中的UIPageViewController翻頁視圖控制器
UIPageViewController更像是一個(gè)視圖容器,將每頁不同的ViewController整合,這里我們將以實(shí)例講解iOS中的UIPageViewController翻頁視圖控制器:2016-06-06Objective-C中類和方法的定義以及協(xié)議的使用
這篇文章主要介紹了Objective-C中類和方法的定義以及協(xié)議的使用,配合Mac下的Xcode IDE進(jìn)行講解,需要的朋友可以參考下2016-01-01iOS實(shí)現(xiàn)翻頁效果動(dòng)畫實(shí)例代碼
本篇文章主要介紹了iOS實(shí)現(xiàn)翻頁效果動(dòng)畫實(shí)例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-05-05iOS實(shí)現(xiàn)的多條折線圖封裝實(shí)例
這篇文章主要跟大家分享了關(guān)于利用iOS實(shí)現(xiàn)多條折線圖的封裝實(shí)例,文中給出了詳細(xì)的示例代碼供大家參考學(xué)習(xí),對(duì)大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起看看吧。2017-07-07