你可以摇一摇请求鸡汤也可以摇一摇分享,只要在摇一摇的方法里面做你想做的事情就好了
//
// ViewController.m
// yaoyiyao
//
// Created by CJW on 16/7/19.
// Copyright © 2016年 cjw. All rights reserved.
//
#import "ViewController.h"
#import <AudioToolbox/AudioToolbox.h>
#import "UIView+DCAnimationKit.h"
@interface ViewController ()
@property (nonatomic,strong)UIImageView * shakeImageView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor redColor];
/***添加支持摇晃**/
[UIApplication sharedApplication].applicationSupportsShakeToEdit = YES;
[self becomeFirstResponder];
self.navigationItem.title = @"JJ天天摇";
//添加图片
UIImageView * imageV = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 198, 198)];
imageV.image = [UIImage imageNamed:@"摇一摇.png"];
[self.view addSubview:imageV];
self.shakeImageView = imageV;
}
//摇一摇方法
-(BOOL)canBecomeFirstResponder
{
return YES;
}
-(void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
NSLog(@"JJ摇动了");
//振动
AudioServicesPlaySystemSound (kSystemSoundID_Vibrate);
//摇动(用到的第三放的 DCAnimationKit 封装)
[self.shakeImageView moveRotation:-40 duration:0.1 finished:^{
[self.shakeImageView moveRotation:80 duration:0.2 finished:^{
[self.shakeImageView moveRotation:-60 duration:0.2 finished:^{
[self.shakeImageView moveRotation:60 duration:0.3 finished:^{
[self.shakeImageView moveRotation:-60 duration:0.3 finished:^{
[self.shakeImageView moveRotation:20 duration:0.4 finished:^{
}];
}];
}];
}];
}];
}];
}
//取消摇动
-(void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
NSLog(@"取消摇");
}
//结束摇 (在这个方法里面请求你要请求的接口)
-(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
NSLog(@"结束摇");
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
本文介绍了一种在iOS应用中实现摇一摇功能的方法,通过使用UIKit和AudioToolbox框架来响应设备的运动事件并执行特定操作,如显示动画效果及播放震动反馈。
1069

被折叠的 条评论
为什么被折叠?



