摇一摇
2016-07-19 11:09
309 查看
你可以摇一摇请求鸡汤也可以摇一摇分享,只要在摇一摇的方法里面做你想做的事情就好了
//
// 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
//
// 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
相关文章推荐
- HTML5使用DeviceOrientation实现摇一摇功能
- 分享网页检测摇一摇实例代码
- 使用PHP实现微信摇一摇周边红包
- javascript html5摇一摇功能的实现
- 安卓系统中实现摇一摇画面振动效果的方法
- 开源中国 OsChina Android 客户端源码分析(5)摇一摇
- javascript html5摇一摇功能的实现
- 微信摇一摇羊年运势签实现?
- 微信功能版(可用于电脑、安卓手机端)微信电脑版 使用说明
- 手机网页摇一摇问题
- ios中摇一摇功能的使用
- 摇一摇
- 摇一摇
- iOS微信摇一摇功能
- iOS实现“摇一摇”与“扫一扫”功能
- ios 实现摇一摇并震动
- Android手机摇一摇功能的简单实现
- android拾遗05——摇一摇开发
- html5实现摇一摇
- html5摇一摇代码优化