iOS 摇一摇的功能
来源:互联网 发布:联通怎么开通4g加网络 编辑:程序博客网 时间:2024/04/29 21:46
#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:245/255.0 green:245/255.0 blue:245/255.0 alpha:1.0]; [self inintImageView]; [self initSoudID];}//初始化振动的图片- (void)inintImageView{ //中间线位置 CGFloat y = 64+(kScreenHeight-64)/2; //图片的比例 宽/高 CGFloat scale = 208/320.0; _topImgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, y-(kScreenWidth*scale), kScreenWidth, kScreenWidth*scale)]; _topImgView.image = [UIImage imageNamed:@"Shake_01"]; [self.view addSubview:_topImgView]; _botImgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 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(0, y_top-50, _topImgView.frame.size.width, _topImgView.frame.size.height); _botImgView.frame = CGRectMake(0, y_bot+50, _botImgView.frame.size.width, _botImgView.frame.size.height); } completion:^(BOOL finished) { [UIView animateWithDuration:0.3 animations:^{ _topImgView.frame = CGRectMake(0, y_top, _topImgView.frame.size.width, _topImgView.frame.size.height); _botImgView.frame = CGRectMake(0, 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
0 0
- iOS 摇一摇的功能
- ios 摇一摇功能的实现
- ios 摇一摇功能的实现
- IOS端的摇一摇功能
- IOS端的摇一摇功能
- IOS端的摇一摇功能
- iOS摇一摇功能的实现
- iOS 摇一摇功能的实现
- IOS手机摇一摇的功能
- iOS 摇一摇功能的实现
- iOS开发之摇一摇功能的实现
- iOS开发之摇一摇功能的实现
- iOS开发之摇一摇功能的实现
- iOS开发之摇一摇功能的实现
- iOS开发之摇一摇功能的实现
- iOS巅峰之摇一摇功能的实现
- iOS的分享功能
- ios的截图功能
- 欧盟对“中国制造”再下黑手
- Kendo UI常用示例汇总(十三)
- app功能测试知识汇总
- RegisterWindowMessage
- 线程执行器
- iOS 摇一摇的功能
- ionic开发中动态设置ion-scroll的高度
- King's Phone
- C++中的堆与拷贝构造函数
- 没有庸俗的企业,只有不停的战场
- kali linux web渗透测试学习笔记
- C++ 11 for-range 访问容器简单实现
- Eclipse解决“Archive for required library: ...”错误
- 正则的贪婪模式/preg_match/preg_match_all