ios实现微信摇一摇功能

时间:2015-07-12 11:11:13   收藏:0   阅读:239

微信摇一摇功能大家想必用过~ ios SDK帮我们完成了所有功作,我们只需要添加相应的逻辑即可

下面贴出实现代码(在对应的ViewController中添加如下代码):

#pragma mark - motion refresh
- (BOOL)canBecomeFirstResponder {
    return YES;
}

- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
    NSLog(@"开始摇动");
    AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);//振动效果
}

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
    NSLog(@"结束摇动");
}

- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event {
    NSLog(@"取消");
}

其中下面代码是为了在摇一摇开始时添加振动效果,需要加入#import <AudioToolbox/AudioToolbox.h>
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);




版权声明:本文为博主原创文章,未经博主允许不得转载。

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!