您的位置:首页 > 移动开发 > IOS开发

iOS巅峰之摇一摇功能的实现

2016-06-07 15:37 645 查看
- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

    

   
// 设置允许摇一摇功能

    [UIApplication sharedApplication].applicationSupportsShakeToEdit = YES;

   
// 并让自己成为第一响应者

    [self becomeFirstResponder];

}

#pragma mark -
摇一摇相关方法

//
摇一摇开始摇动

- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {

    NSLog(@"开始摇动");

    return;

}

//
摇一摇取消摇动

- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event {

    NSLog(@"取消摇动");

    return;

}

//
摇一摇摇动结束

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {

    if (event.subtype == UIEventSubtypeMotionShake) { //
判断是否是摇动结束

        NSLog(@"摇动结束");

    }

    return;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  iOS 摇一摇 动画