星空网 > 软件开发 > 操作系统

iOS 摇一摇的功能

效果如下

iOS 摇一摇的功能images/loading.gif' data-original="http://images2015.cnblogs.com/blog/818241/201606/818241-20160613084926463-833839218.gif" />

相关素材

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: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




原标题:iOS 摇一摇的功能

关键词:IOS

IOS
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

物流放假:https://www.goluckyvip.com/tag/9819.html
惠东货运物流:https://www.goluckyvip.com/tag/98190.html
惠东物流货运:https://www.goluckyvip.com/tag/98191.html
大亚湾 物流:https://www.goluckyvip.com/tag/98192.html
东港货运物流:https://www.goluckyvip.com/tag/98193.html
南关货运物流:https://www.goluckyvip.com/tag/98194.html
夹江千佛岩景区门票(夹江千佛岩景区门票价格):https://www.vstour.cn/a/411232.html
武陵山大裂谷周围景点 武陵山大裂谷周围景点图片:https://www.vstour.cn/a/411233.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流