iOS-OC-仿微信搖一搖
//
// ViewController.m
// 搖一搖
//
// Created by ZFJ_APPLE on 16/1/25.
// Copyright © 2016年張福傑. All rights reserved.
//
#import "ViewController.h"
#import "LZAudioTool.h"
#import <AVFoundation/AVFoundation.h>
#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
Demo下載地址:http://pan.baidu.com/s/1bohohIJ
相關文章
- Android利用感測器實現-仿微信搖一搖Android
- HTML5 語音聊天 IM|仿微信語音介面|搖一搖效果HTML
- swift實現仿知乎搖一搖彈出框Swift
- iOS微信朋友圈與搖一搖iOS
- 微信搖一搖的一個有趣應用
- html5版聊天室|仿微信語音|搖一搖|地圖定位HTML地圖
- 實現微信搖一搖功能簡單介紹
- 微信IOS中搖一搖無法播放聲音iOS
- Flutter 實現微信搖一搖的功能 Flutter 加速度感應Flutter
- Android搖一搖、螢幕方向的監聽Android
- iOS通過加速計計算搖一搖次數iOS
- 如何用純 CSS 創作一個搖搖晃晃的 loaderCSS
- 搖桿程式
- 不會吧,這也行?iOS後臺鎖屏監聽搖一搖iOS
- 和 transformjs 一起搖擺ORMJS
- 和transformjs一起搖擺ORMJS
- webpack 搖樹處理Web
- 盤點叫車App市場:嘀嘀、搖搖、易叫車列前三APP
- 價格離譜的配件,與蘋果搖搖欲墜的奢侈品人設蘋果
- IT的消費化:尾巴搖狗
- 天體搖擺儀的工作原理
- Unity——EasyTouch搖桿外掛使用Unity
- Android joystick,安卓模擬搖桿Android安卓
- 【canvas】搖桿操控飛船的動畫原理Canvas動畫
- 堅持“動態清零”不動搖
- anroid Api demo自帶的一個shake(搖頭)效果API
- 趣玩Python——利用python搖身一變社會人Python
- Android搖晃重新整理實用教程Android
- Java地位無可動搖的12個原因Java
- iOS--手把手教你一步一步完成搖骰子動畫iOS動畫
- 韓國巨型機器人曝光,走一步地動山搖機器人
- 搖身一變,ADSL貓進化為無線路由器路由器
- R星:我的成功,源自我的搖滾核心
- 穀粒joycon霍爾電磁搖桿釋出
- HTML5 3D衣服搖擺動畫特效HTML3D動畫特效
- 讓我們一起搖擺,AR應用DanceReality助你記住舞步
- 為什麼內推成了遊戲人的搖錢樹?遊戲
- 服務網格GCP (GKE, Istio, MSA) 搖滾組合GC