效果如下

相关素材

相关代码如下

#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 摇一摇的功能的更多相关文章

  1. iOS开发——高级技术&摇一摇功能的实现

    摇一摇功能的实现 在AppStore中多样化功能越来越多的被使用了,所以今天就开始介绍一些iOS开发的比较实用,但是我们接触的比较少的功能,我们先从摇一摇功能开始 在 UIResponder中存在这么 ...

  2. IOS开发之——类似微信摇一摇的功能实现

    首先,一直以为摇一摇的功能实现好高大上,结果百度了.我自己也模仿写了一个demo.主要代码如下: 新建一个项目,名字为AnimationShake. 主要代码: - (void)motionBegan ...

  3. iOS摇一摇功能、震动功能、简单的摇动动画、生成二维码图片与发送短信等几个功能

    有一个开锁的功能,具体的需求就类似于微信的"摇一摇"功能:摇动手机,手机震动,手机上的锁的图片摇动一下,然后发送开锁指令.需求简单,但用到了许多方面的知识. 1.摇一摇 相对这是最 ...

  4. iOS 手机摇一摇功能

    调用手机摇一摇功能其实很简单,在你调用的控制器的 viewDidLoad方法里调用 [UIApplication sharedApplication].applicationSupportsShake ...

  5. IOS端的摇一摇功能

    //微信的摇一摇是怎么实现的~发现原来 ios本身就支持 //在 UIResponder中存在这么一套方法 - (void)motionBegan:(UIEventSubtype)motion wit ...

  6. IOS中摇一摇实现截屏(可实现问题反馈的功能)

    有一段时间没有更新博客了,今天更新一篇关于最近工作中用到的一个功能,先简单描述一下:我们知道,测试人员在测试客户端产品时,当出现问题或者BUG的时候,都得先对页面截图,然后从相册中选择截图,加上一段描 ...

  7. iOS几个功能:1.摇一摇;2.震动;3.简单的摇动动画;4.生成二维码图片;5.发送短信;6.播放网络音频等

    有一个开锁的功能,具体的需求就类似于微信的“摇一摇”功能:摇动手机,手机震动,手机上的锁的图片摇动一下,然后发送开锁指令.需求简单,但用到了许多方面的知识. 1.摇一摇 相对这是最简单的功能了. 在v ...

  8. 几行代码实现iOS摇一摇功能

    实现这个功能很简单,我们直接看代码 - (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event{ NSLog(@&quo ...

  9. iOS 摇一摇功能的实现

    在 UIResponder中存在这么一套方法 - (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event __OSX_A ...

  10. ios摇一摇功能

    在 UIResponder中存在这么一套方法 - (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event __OSX_A ...

随机推荐

  1. 使用Ubuntu 12.04作为日常电脑环境

    搜狗输入法出来之后,我觉得有必要写一篇博客说明一下,如何使用Ubuntu作为日常的电脑系统.我使用的Ubuntu版本是12.04,没有使用Ubuntukylin,因为的电脑比较老,使用那个版本,电脑有 ...

  2. 为SubSonic3.0的查询(SubSonic.Query.Select和存储过程)添加更多的执行功能

    在使用SubSonic3.0的查询功能时,会发现想通过执行返回我们想要的数据,切没有相关的功能,比如说:SubSonic.Query.Select,在使用查询时没有返回DataSet或DataTabl ...

  3. CDH安装失败了,如何重新安装

    1> 删除Agent节点的UUID # rm -rf /opt/cm-5.4.7/lib/cloudera-scm-agent/* 2>  清空主节点CM数据库 进入主节点的Mysql数据 ...

  4. [c++] Smart Pointers

    内存管理方面的知识 基础实例: #include <iostream> #include <stack> #include <memory> using names ...

  5. php通过判断来源主机头进行防盗链

    check.php <html> <body> <form action="test.php" method="post"> ...

  6. 记录一则ORA-12154,ORA-12560解决过程

    应用服务器:Windows Server 2008 R2 Enterprise 故障现象:项目侧同事反映应用服务器上的程序连接数据库报错:ORA-12560: TNS: 协议适配器错误 1.故障重现 ...

  7. Linux入门

    参考资料:http://www.92csz.com/study/linux/ [Linux系统目录结构] 登录系统后,在当前命令窗口下输入 ls / 你会看到 以下是对这些目录的解释: /bin bi ...

  8. WebGIS中解决使用Lucene进行兴趣点搜索排序的两种思路

    文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/. 1.背景 目前跟信息采集相关的一个项目提出了这样的一个需求:中国银行等 ...

  9. TF-IDF提取行业关键词

    1. TF-IDF简介 TF-IDF(Term Frequency/Inverse Document Frequency)是信息检索领域非常重要的搜索词重要性度量:用以衡量一个关键词\(w\)对于查询 ...

  10. BizTalk动手实验(十七)ODBC适配器使用

    更多内容请查看:BizTalk动手实验系列目录                       BizTalk 开发系列 1 课程简介 通过本课程熟悉ODBC适配器的的使用,本练习采用BizTalk 20 ...