iOS 摇一摇的功能
效果如下

相关素材

相关代码如下
#import "ShakeViewController.h"
#import <AudioToolbox/AudioToolbox.h>
#import <AVFoundation/AVFoundation.h> #define kScreenWidth [UIScreen mainScreen].bounds.size.width
#define kScreenHeight [UIScreen mainScreen].bounds.size.height @interface ShakeViewController () @property (nonatomic,strong)UIImageView *topImgView;
@property (nonatomic,strong)UIImageView *botImgView; @property (nonatomic) SystemSoundID soundID; @end @implementation ShakeViewController - (void)viewDidLoad {
[super viewDidLoad]; [UIApplication sharedApplication].applicationSupportsShakeToEdit = YES;
[self becomeFirstResponder];
self.view.backgroundColor = [UIColor colorWithRed:/255.0
green:/255.0
blue:/255.0
alpha:1.0]; [self inintImageView];
[self initSoudID];
} //初始化振动的图片
- (void)inintImageView
{
//中间线位置
CGFloat y = +(kScreenHeight-)/;
//图片的比例 宽/高
CGFloat scale = /320.0; _topImgView = [[UIImageView alloc]initWithFrame:CGRectMake(, y-(kScreenWidth*scale), kScreenWidth, kScreenWidth*scale)];
_topImgView.image = [UIImage imageNamed:@"Shake_01"];
[self.view addSubview:_topImgView]; _botImgView = [[UIImageView alloc]initWithFrame:CGRectMake(, y, kScreenWidth, kScreenWidth*scale)];
_botImgView.image = [UIImage imageNamed:@"Shake_02"];
[self.view addSubview:_botImgView];
} //对soundID进行赋值
- (void)initSoudID
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"shake_sound_male" ofType:@"wav"];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:path], &_soundID);
} /*************************** 振动检测 ******************************/
-(void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
//播放
AudioServicesPlaySystemSound (_soundID); CGFloat y_top = _topImgView.frame.origin.y;
CGFloat y_bot = _botImgView.frame.origin.y; [UIView animateWithDuration:0.3 animations:^{ _topImgView.frame = CGRectMake(, y_top-, _topImgView.frame.size.width, _topImgView.frame.size.height);
_botImgView.frame = CGRectMake(, y_bot+, _botImgView.frame.size.width, _botImgView.frame.size.height); } completion:^(BOOL finished) { [UIView animateWithDuration:0.3 animations:^{ _topImgView.frame = CGRectMake(, y_top, _topImgView.frame.size.width, _topImgView.frame.size.height);
_botImgView.frame = CGRectMake(, y_bot, _botImgView.frame.size.width, _botImgView.frame.size.height); } completion:^(BOOL finished) { }]; }];
} -(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
[self performSelector:@selector(vibrate) withObject:nil afterDelay:0.6];
} -(void)vibrate
{
//振动
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
} @end
iOS 摇一摇的功能的更多相关文章
- iOS开发——高级技术&摇一摇功能的实现
摇一摇功能的实现 在AppStore中多样化功能越来越多的被使用了,所以今天就开始介绍一些iOS开发的比较实用,但是我们接触的比较少的功能,我们先从摇一摇功能开始 在 UIResponder中存在这么 ...
- IOS开发之——类似微信摇一摇的功能实现
首先,一直以为摇一摇的功能实现好高大上,结果百度了.我自己也模仿写了一个demo.主要代码如下: 新建一个项目,名字为AnimationShake. 主要代码: - (void)motionBegan ...
- iOS摇一摇功能、震动功能、简单的摇动动画、生成二维码图片与发送短信等几个功能
有一个开锁的功能,具体的需求就类似于微信的"摇一摇"功能:摇动手机,手机震动,手机上的锁的图片摇动一下,然后发送开锁指令.需求简单,但用到了许多方面的知识. 1.摇一摇 相对这是最 ...
- iOS 手机摇一摇功能
调用手机摇一摇功能其实很简单,在你调用的控制器的 viewDidLoad方法里调用 [UIApplication sharedApplication].applicationSupportsShake ...
- IOS端的摇一摇功能
//微信的摇一摇是怎么实现的~发现原来 ios本身就支持 //在 UIResponder中存在这么一套方法 - (void)motionBegan:(UIEventSubtype)motion wit ...
- IOS中摇一摇实现截屏(可实现问题反馈的功能)
有一段时间没有更新博客了,今天更新一篇关于最近工作中用到的一个功能,先简单描述一下:我们知道,测试人员在测试客户端产品时,当出现问题或者BUG的时候,都得先对页面截图,然后从相册中选择截图,加上一段描 ...
- iOS几个功能:1.摇一摇;2.震动;3.简单的摇动动画;4.生成二维码图片;5.发送短信;6.播放网络音频等
有一个开锁的功能,具体的需求就类似于微信的“摇一摇”功能:摇动手机,手机震动,手机上的锁的图片摇动一下,然后发送开锁指令.需求简单,但用到了许多方面的知识. 1.摇一摇 相对这是最简单的功能了. 在v ...
- 几行代码实现iOS摇一摇功能
实现这个功能很简单,我们直接看代码 - (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event{ NSLog(@&quo ...
- iOS 摇一摇功能的实现
在 UIResponder中存在这么一套方法 - (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event __OSX_A ...
- ios摇一摇功能
在 UIResponder中存在这么一套方法 - (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event __OSX_A ...
随机推荐
- 连接 insance 到 vlan101 - 每天5分钟玩转 OpenStack(97)
前面我们创建了 vlan101,今天继续部署 instance 到该 vlan network, 并讨论 instance 之间的连通性. launch 新的 instance "cirro ...
- 关于SVN链接服务器Unable to connect to a repository at URL*报错问题
在BAE上托管了写代码,想用SVN做版本控制,可是死活连不上,但用Dreamweave可以连上,整了半天是dan疼的缓存问题,清一下缓存就OK了. TortoiseSVN->Setting-&g ...
- iOS开发使用半透明模糊效果方法整理
虽然iOS很早就支持使用模糊效果对图片等进行处理,但尤其在iOS7以后,半透明模糊效果得到大范围广泛使用.包括今年最新发布的iOS8也沿袭了这一设计,甚至在OS X 10.10版Yosemite中也开 ...
- MySQL入门01-MySQL源码安装
操作系统:CentOS 6.7 MySQL版本:5.6.30 1.前期准备 2.系统配置 3.CMake编译配置 4.make && make install 5.后期配置和测试 Re ...
- java删除文件夹
想删除本地一个项目目录,结果windows说路径太长,不能删除.于是试了试java删除.一切ok.以后一定要抓紧时间学python. /** * Created by rmiao on 4/21/20 ...
- C#图片加水印实例与代码
本文要提供的类可以为图片加文字水印,以及判断是否是图片文件.经过测试可运行,例子请下载:http://hovertree.com/h/bjaf/5qc5eh6y.htm 例子效果图: 以下是Hover ...
- 【C#】DataRowState演变备忘
环境:.net 2.0 DataRow的行状态一段时间不用就会吃不准,记录一下,备查. DataRowState 演变表 行属于如下状态时进行右边操作→ 后的状态演变 添加到表 dt.Rows.Add ...
- IBC编程社区
IBC编程社区-.NET编程交流论坛 官方地址:http://www.ibcibc.com 新浪微博:IBC编程社区 微信公众号:ibcbcsq QQ一群:235371874(已满) QQ二群:248 ...
- java for循环冒泡排序
int[]a =new int[]{7,19,66,21,88,40}; for(int i=1;i<=a.length-1;i++){ //比总长度减1趟就排好序了.因为每一趟出一个值. fo ...
- 【夯实PHP基础系列】linux下yum安装PHP APC
Alternative PHP Cache(可选PHP缓存),依赖于 PECL扩展库 用源码方式安装,直接yum就行了:首先要安装apc的依赖包:yum install php-pear php-de ...