iOS仿微信搖一搖功能
更新時間:2018年05月23日 09:54:17 作者:獅兄
這篇文章主要為大家詳細介紹了iOS仿微信搖一搖功能的實現(xiàn)方法
,具有一定的參考價值,感興趣的小伙伴們可以參考一下
iOS仿照微信搖一搖功能實現(xiàn)
一、描述
需要做一個界面,仿照微信搖一搖,獲取接口進行簽到功能。
首先明確以下幾點:
1、需要震動。
2、需要聲音。(準備好mp3音效)
二、直接貼代碼
/ Created by 石雄偉 on 16/7/29. // Copyright © 2016年 石雄偉. All rights reserved. // #import "SignBoardViewController.h" #import <AVFoundation/AVFoundation.h> #import <AudioToolbox/AudioToolbox.h> #import <CoreAudio/CoreAudioTypes.h> @interface SignBoardViewController () { } @property (nonatomic,strong) AVAudioPlayer * audioPlayer; @end @implementation SignBoardViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. //設置導航 [self makeNav]; } #pragma mark 定制Nav - (void)makeNav { [self.navigationItem setTitle:@"每日簽到"];//改寫title //修改導航按鈕,并且修改響應方法 self.leftButton.frame = CGRectMake(0, 0, 13, 20); [self.leftButton setBackgroundImage:[UIImage imageNamed:@"NavBack"] forState:UIControlStateNormal]; self.leftButton.layer.cornerRadius = 0; self.leftButton.layer.masksToBounds = NO; self.leftButton.layer.borderColor = [UIColor clearColor].CGColor; //添加點擊方法 [self.leftButton addTarget:self action:@selector(navLeftClick) forControlEvents:UIControlEventTouchUpInside]; //隱藏 右邊按鈕 self.rightButton.hidden= YES; } #pragma mark nav左邊導航按鈕方法重寫,返回按鈕 - (void)navLeftClick { [self dismissViewControllerAnimated:YES completion:^{ nil; }]; } #pragma mark - #pragma mark 點擊 - (void)touchesBegan:(nonnull NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event { NSLog(@"點擊,觸摸方法等"); AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); } #pragma mark - #pragma mark 搖動開始 - (void)motionBegan:(UIEventSubtype)motion withEvent:(nullable UIEvent *)event { NSLog(@"begin motion"); } #pragma mark - #pragma mark 搖動結束 - (void)motionEnded:(UIEventSubtype)motion withEvent:(nullable UIEvent *)event { NSLog(@"end motion"); if (motion ==UIEventSubtypeMotionShake ) { //播放音效 SystemSoundID soundID; // shake_sound_male.mp3 NSString *path = [[NSBundle mainBundle ] pathForResource:@"shake_sound_male" ofType:@"mp3"]; AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:path], &soundID); AudioServicesPlaySystemSound (soundID); //設置震動 AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); } } #pragma mark - #pragma mark 搖動取消 - (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event { } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
iOS實現(xiàn)自定義購物車角標顯示購物數(shù)量(添加商品時角標抖動 Vie)
本文主要介紹了iOS實現(xiàn)自定義購物車及角標顯示購物數(shù)量(添加商品時角標抖動 Vie)的相關知識。具有很好的參考價值。下面跟著小編一起來看下吧2017-04-04iOS開發(fā)中如何優(yōu)雅的調(diào)試數(shù)據(jù)庫詳解
這篇文章主要給大家介紹了關于iOS開發(fā)中如何優(yōu)雅的調(diào)試數(shù)據(jù)庫的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧。2017-12-12iOS開發(fā)使用UITableView制作N級下拉菜單的示例
這篇文章主要介紹了iOS開發(fā)使用UITableView制作N級下拉菜單的示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-01-01iOS App開發(fā)中使用及自定義UITableViewCell的教程
這篇文章主要介紹了iOS App開發(fā)中使用及自定義UITableViewCell的教程,自定義TableViewCell文中使用Objective-C演示而非ib,需要的朋友可以參考下2016-04-04