微信搖一搖外掛程式ios iOS 仿微信搖一搖

2021-10-13 12:17:30 字數 2530 閱讀 4646

釋放雙眼,帶上耳機,聽聽看~!

// viewcontroller.m

// 搖一搖

#import "viewcontroller.h"

#import "lzaudiotool.h"

#import

#define kwidth [uiscreen mainscreen].bounds.size.width

#define kheight [uiscreen mainscreen].bounds.size.height

@inte***ce viewcontroller ()

@property (nonatomic,strong) uiimageview *upimage; //背景

@property (nonatomic,strong) uiview *upview; //下一半手

@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:@"[email protected]"];

[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:@"[email protected]"];

[_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:@"[email protected]"];

[_downview addsubview:_downimage];

[self.view addsubview:_downview];

#pragma mark - 開始搖晃就會呼叫

- (void)motionbegan:(uieventsubtype)motion withevent:(uievent *)event

//開始搖晃設定動畫

[uiview animatewithduration:1 animations:^ completion:^(bool finished) completion:^(bool finished) {

[uiview animatewithduration:1 animations:^{

_downview.frame = cgrectmake(0, kheight /2, kwidth, kheight / 2);

[lzaudiotool playmusic:@"1.***"];

#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

微信搖一搖原理

1 感測器 sensor 是什麼?感測器是能標識溫度,加速度等等物理現象的轉換電子訊號的機器。android sdk,在移動裝置中提供了各種各樣的感測器的api。2 感測器型別 方向 加速表 光線 磁場 臨近性 溫度等。3 sensorlistener介面是感測器應用程式的中心,它包括兩個必需方法 ...

微信小程式 搖一搖

小程式雖然沒有提供搖一搖api介面,但是也乙個加速器api 加上搜尋一些大神的資料,我這裡就做了乙個dome,1.模擬資料,從m陣列裡面,每次搖一下就隨機獲取一條資訊出來,每搖一次就顯示不同的資料,注 真正的時候是通過介面返回資料的,因此後台處理好隨機產生一條資料,然後前台就獲取,響應速度也加快。官...

仿微信搖一搖實現搖動開始與結束監聽

安卓端做搖一搖,主要運用到sensormanager 這個類,通過重力感測器,獲取xyz三軸的位置變化,來判斷是否是搖動。注意 手機震動需要加入震動許可權 android.permission.vibrate 一 sensormanager 初始化 註冊sensormanager 獲取 sensor...