摇一摇

来源:互联网 发布:怎么延长淘宝收货时间 编辑:程序博客网 时间:2024/05/16 06:07

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


//

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

    [superviewDidLoad];

    self.view.backgroundColor = [UIColorredColor];

    /***添加支持摇晃**/

    [UIApplicationsharedApplication].applicationSupportsShakeToEdit =YES;

    [selfbecomeFirstResponder];

    

    self.navigationItem.title =@"JJ天天摇";

    

    //添加图片

    UIImageView * imageV = [[UIImageViewalloc]initWithFrame:CGRectMake(100,100, 198,198)];

    imageV.image = [UIImageimageNamed:@"摇一摇.png"];

    [self.viewaddSubview:imageV];

    self.shakeImageView = imageV;

}

//摇一摇方法

-(BOOL)canBecomeFirstResponder

{

    returnYES;

}

-(void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event

{

    NSLog(@"JJ摇动了");

    //振动

    AudioServicesPlaySystemSound (kSystemSoundID_Vibrate);

    //摇动(用到的第三放的 DCAnimationKit封装)

    [self.shakeImageViewmoveRotation:-40duration:0.1finished:^{

        [self.shakeImageViewmoveRotation:80duration:0.2finished:^{

            [self.shakeImageViewmoveRotation:-60duration:0.2finished:^{

                [self.shakeImageViewmoveRotation:60duration:0.3finished:^{

                    [self.shakeImageViewmoveRotation:-60duration:0.3finished:^{

                        [self.shakeImageViewmoveRotation:20duration:0.4finished:^{

                            

                        }];

                    }];

                }];

            }];

        }];

    }];

}

//取消摇动

-(void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event

{

    NSLog(@"取消摇");

}

//结束摇(在这个方法里面请求你要请求的接口)

-(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event

{

    NSLog(@"结束摇");

}


- (void)didReceiveMemoryWarning {

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end



0 0
原创粉丝点击