您的位置:首页 > 其它

摇一摇

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  摇一摇