没有合适的资源?快使用搜索试试~ 我知道了~
“摇一摇”功能的实现: iPhone对 “摇一摇”有很好的支持,总体说来就两步: 在视图控制器中打开接受“摇一摇”的开关; - (void)viewDidLoad { // 设置允许摇一摇功能 [UIApplication sharedApplication].applicationSupportsShakeToEdit = YES; // 并让自己成为第一响应者 [self becomeFirstResponder]; } 在“摇一摇”触发的制定的方法中实现需要实现的功能(”摇一摇“检测方法)。 // 摇一摇开始摇动 - (void)motionBegan:(UIE
资源推荐
资源详情
资源评论
iOS实现实现“摇一摇摇一摇”与与“扫一扫扫一扫”功能示例代码功能示例代码
“摇一摇摇一摇”功能的实现:功能的实现:
iPhone对 “摇一摇”有很好的支持,总体说来就两步:
在视图控制器中打开接受“摇一摇”的开关;
- (void)viewDidLoad {
// 设置允许摇一摇功能
[UIApplication sharedApplication].applicationSupportsShakeToEdit = YES;
// 并让自己成为第一响应者
[self becomeFirstResponder];
}
在“摇一摇”触发的制定的方法中实现需要实现的功能(”摇一摇“检测方法)。
// 摇一摇开始摇动
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
NSLog(@"开始摇动");
//添加“摇一摇”动画
[self addAnimations];
//音效
AudioServicesPlaySystemSound (soundID);
return;
}
// “摇一摇”取消摇动
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event {
NSLog(@"取消摇动");
return;
}
// “摇一摇”摇动结束
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if (event.subtype == UIEventSubtypeMotionShake) { // 判断是否是摇动结束
NSLog(@"摇动结束");
}
return;
}
”摇一摇“的动画效果:
- (void)addAnimations {
//音效
AudioServicesPlaySystemSound (soundID);
//让上面图片的上下移动
CABasicAnimation *translation2 = [CABasicAnimation animationWithKeyPath:@"position"];
translation2.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
translation2.fromValue = [NSValue valueWithCGPoint:CGPointMake(160, 115)];
translation2.toValue = [NSValue valueWithCGPoint:CGPointMake(160, 40)];
translation2.duration = 0.4;
translation2.repeatCount = 1;
translation2.autoreverses = YES;
//让下面的图片上下移动
CABasicAnimation *translation = [CABasicAnimation animationWithKeyPath:@"position"];
translation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
translation.fromValue = [NSValue valueWithCGPoint:CGPointMake(160, 345)];
translation.toValue = [NSValue valueWithCGPoint:CGPointMake(160, 420)];
translation.duration = 0.4;
translation.repeatCount = 1;
translation.autoreverses = YES;
[imgDown.layer addAnimation:translation forKey:@"translation"];
[imgUp.layer addAnimation:translation2 forKey:@"translation2"];
}
注意:在模拟器中运行时,可以通过「Hardware」-「Shake Gesture」来测试「摇一摇」功能。如下:
资源评论
weixin_38665162
- 粉丝: 1
- 资源: 927
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功