Sian 发表于 2015-4-21 12:13:01

iOS摇一摇的使用

本帖最后由 Sian 于 2015-4-21 12:14 编辑

一、实现系统自带的motionBegan方法
/// 开始
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event NS_AVAILABLE_IOS(3_0);
/// 结束
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event NS_AVAILABLE_IOS(3_0);
/// 取消
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event NS_AVAILABLE_IOS(3_0);

假如程序不响应此方法,再实现以下方法:
- (BOOL)canBecomeFirstResponder
{
    return YES;
}

二、motionBegan+通知的方法(建议)
1.在Appdelegate里写motionBegan方法
-(void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
    [ postNotificationName:@"SAMotionBegan" object:@(motion)];
}

2.在需要接收通知的页面添加通知
- (void)viewWillAppear:(BOOL)animated
{
    ;
    ;
}

- (void)shake
{
    SALog(@"摇一摇开始...");
}
页: [1]
查看完整版本: iOS摇一摇的使用