摇一摇

    你可以摇一摇请求鸡汤也可以摇一摇分享,只要在摇一摇的方法里面做你想做的事情就好了


//

//  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



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值