摇一摇
来源:互联网 发布:uwp下载软件 编辑:程序博客网 时间:2024/06/05 03:23
- (void)viewDidLoad {
[superviewDidLoad];
// 设置允许摇一摇功能
[UIApplicationsharedApplication].applicationSupportsShakeToEdit =YES;
// 并让自己成为第一响应者
[selfbecomeFirstResponder];
}
#pragma mark - 摇一摇相关方法
// 摇一摇开始摇动
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
NSLog(@"开始摇动");
//播放声音
SystemSoundID soundID;
NSString *path =@"/System/Library/Audio/UISounds/sms-received1.caf";
AudioServicesCreateSystemSoundID((__bridgeCFURLRef_Nonnull)([NSURLfileURLWithPath:path]), &soundID);
AudioServicesPlayAlertSound(soundID);
//播放震动
//AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
return;
}
// 摇一摇取消摇动
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event {
NSLog(@"取消摇动");
return;
}
// 摇一摇摇动结束
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if (event.subtype ==UIEventSubtypeMotionShake) {// 判断是否是摇动结束
NSLog(@"摇动结束");
}
return;
}
//创建动画 CAKeyframeAnimation * keyAnimaion = [CAKeyframeAnimation animation]; keyAnimaion.keyPath = @"transform.rotation"; keyAnimaion.values = @[@(-10 / 180.0 * M_PI),@(10 /180.0 * M_PI),@(-10/ 180.0 * M_PI)];//度数转弧度 keyAnimaion.removedOnCompletion = NO; keyAnimaion.fillMode = kCAFillModeForwards; keyAnimaion.duration = 0.3; keyAnimaion.repeatCount = MAXFLOAT; [self.iconImageView.layer addAnimation:keyAnimaion forKey:nil];
- 摇一摇
- 摇一摇
- 摇一摇。。
- 摇一摇
- 摇一摇
- 摇一摇
- 摇一摇
- 摇一摇
- 摇一摇
- 摇一摇
- 摇一摇
- 摇一摇
- 摇一摇
- 摇一摇
- Android摇一摇
- iOS摇一摇
- “摇一摇”功能
- 摇一摇看电影
- Mac下教你如何使用Github客户端开源项目
- Ehcache技术详解
- Leetcode 64. Minimum Path Sum (Medium) (cpp)
- Caffe和MatConvNet安装
- UIStackView
- 摇一摇
- 判断线程运行状态的两种方法
- HIHOCODER KMP
- 浅谈属性动画
- PyQt5教程-01-最简单的窗口
- POJ1743Musical Theme求解不重叠的最长子串长度(后缀数组+二分求解)
- mget 同时获取
- TextView常用功能
- 2016 多校3 1009 Palindrome Bo 回文串dp+优化