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;
//添加長(zhǎng)按手勢(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];
}
以上就是本文的全部?jī)?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)自定義購(gòu)物車角標(biāo)顯示購(gòu)物數(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)問(wèn)題
- iOS自定義button抖動(dòng)效果并實(shí)現(xiàn)右上角刪除按鈕
- 仿iOS圖標(biāo)抖動(dòng)
相關(guān)文章
iphone的safari瀏覽器中實(shí)現(xiàn)全屏瀏覽的方法
這篇文章主要介紹了iphone的safari瀏覽器中實(shí)現(xiàn)全屏瀏覽的方法,同時(shí)介紹了Add to Home Screen功能的實(shí)現(xiàn)方法,需要的朋友可以參考下2014-06-06
iOS如何保持程序在后臺(tái)長(zhǎng)時(shí)間運(yùn)行
這篇文章主要為大家詳細(xì)介紹了iOS如何保持程序在后臺(tái)長(zhǎng)時(shí)間運(yùn)行,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-09-09
iOS開發(fā)中ViewController的頁(yè)面跳轉(zhuǎn)和彈出模態(tài)
這篇文章主要介紹了iOS開發(fā)中ViewController的頁(yè)面跳轉(zhuǎn)和彈出模態(tài),ViewController是MVC開發(fā)模式中一個(gè)重要的類,需要的朋友可以參考下2015-10-10
解決ios端點(diǎn)擊按鈕閃爍問(wèn)題(小tips)
這篇文章主要介紹了ios端點(diǎn)擊按鈕閃爍的解決方法(小tips),需要的朋友參考下吧2017-10-10
解析iOS內(nèi)存不足時(shí)的警告以及處理過(guò)程
這篇文章主要介紹了iOS內(nèi)存不足時(shí)的警告以及處理過(guò)程,包括View Controller和生命周期等相關(guān)方面的知識(shí),需要的朋友可以參考下2015-10-10
iOS通過(guò)Runtime實(shí)現(xiàn)友盟統(tǒng)計(jì)的實(shí)例代碼
本篇文章主要介紹了iOS通過(guò)Runtime實(shí)現(xiàn)友盟統(tǒng)計(jì)的實(shí)例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-06-06
iOS開發(fā)中蘋果輸入手機(jī)號(hào)變用戶的名字
今天我們的用戶輸入手機(jī)號(hào)之后變成了用戶的名字,沒(méi)辦法獲取驗(yàn)證碼,因?yàn)槭謾C(jī)格式不對(duì)。下面通過(guò)本文給大家分享開發(fā)中蘋果輸入手機(jī)號(hào)變用戶的名字,需要的朋友可以參考下2017-05-05
iOS開發(fā)總結(jié)之UILabel常用屬性介紹
下面小編就為大家分享一篇iOS開發(fā)總結(jié)之UILabel常用屬性介紹,具有很的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2017-12-12

