微信摇一摇插件ios_iOS-仿微信摇一摇

释放双眼,带上耳机,听听看~!

//

// ViewController.m

// 摇一摇

//

// Created by ZFJ_APPLE on 16/1/25.

// Copyright © 2016年张福杰. All rights reserved.

//

#import "ViewController.h"

#import "LZAudioTool.h"

#import

#define kWidth [UIScreen mainScreen].bounds.size.width

#define kHeight [UIScreen mainScreen].bounds.size.height

@interface ViewController ()

@property (nonatomic,strong) UIImageView *upImage; //背景图片

@property (nonatomic,strong) UIImageView *downImage; //上一半手的图片

@property (nonatomic,strong) UIView *upView; //下一半手

@property (nonatomic,strong) UIView *downView; //下一半手的图片

@end

@implementation ViewController

- (void)viewDidLoad

{

[superviewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

[self uiConfig];

}

- (void)uiConfig

{

UIImageView *image = [[UIImageViewalloc]initWithFrame:CGRectMake(0,kHeight / 4,kWidth, kHeight /2)];

image.image = [UIImageimageNamed:@"ShakeHideImg_women@2x.png"];

[self.viewaddSubview:image];

_upView = [[UIView alloc]initWithFrame:CGRectMake(0,0, kWidth, kHeight / 2)];

_upView.backgroundColor = [UIColor blackColor];

_upImage = [[UIImageView alloc]initWithFrame:CGRectMake(50, kHeight /4, kWidth - 100, kHeight /4)];

_upImage.image = [UIImage imageNamed:@"Shake_Logo_Up@2x.png"];

[_upView addSubview:_upImage];

[self.view addSubview:_upView];

_downView = [[UIView alloc]initWithFrame:CGRectMake(0, kHeight /2, kWidth, kHeight / 2)];

_downView.backgroundColor = [UIColor blackColor];

_downImage = [[UIImageView alloc]initWithFrame:CGRectMake(50,0, kWidth - 100, kHeight /4)];

_downImage.image = [UIImage imageNamed:@"Down@2x.png"];

[_downView addSubview:_downImage];

[self.view addSubview:_downView];

}

#pragma mark - 开始摇晃就会调用

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

{

//开始摇晃设置动画

[UIView animateWithDuration:1 animations:^{

_upView.frame = CGRectMake(0, -(kHeight /4), kWidth, kHeight / 2);

} completion:^(BOOL finished) {

[UIView animateWithDuration:1 animations:^{

_upView.frame = CGRectMake(0, 0, kWidth, kHeight / 2);

}];

}];

[UIView animateWithDuration:1 animations:^{

_downView.frame = CGRectMake(0, kHeight /2 + kHeight / 4, kWidth, kHeight /2);

} completion:^(BOOL finished) {

[UIView animateWithDuration:1 animations:^{

_downView.frame = CGRectMake(0, kHeight /2, kWidth, kHeight / 2);

}];

}];

//播放摇晃声音

[LZAudioTool playMusic:@"1.mp3"];

}

#pragma mark - 摇晃结束就会调用

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

{

AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

//摇晃结束

}

#pragma mark - 摇晃被打断就会调用

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

{

//摇晃被打断

}

- (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、付费专栏及课程。

余额充值