国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > iOS > 正文

iOS實現(xiàn)微信搖一搖功能

2020-07-26 02:26:31
字體:
供稿:網(wǎng)友

一、描述

需要做一個界面,仿照微信搖一搖,獲取接口進行簽到功能。
首先明確以下幾點:

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.  //設(shè)置導(dǎo)航  [self makeNav];}#pragma mark 定制Nav- (void)makeNav{  [self.navigationItem setTitle:@"每日簽到"];//改寫title  //修改導(dǎo)航按鈕,并且修改響應(yīng)方法  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左邊導(dǎo)航按鈕方法重寫,返回按鈕- (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 搖動結(jié)束- (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);    //設(shè)置震動    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)容,希望對大家的學習有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 葫芦岛市| 彝良县| 玛曲县| 瑞丽市| 万年县| 稻城县| 衡水市| 航空| 双桥区| 北流市| 博爱县| 泰州市| 沈阳市| 昭觉县| 区。| 东明县| 深州市| 东台市| 平遥县| 邹城市| 安康市| 阿勒泰市| 内丘县| 松江区| 丰原市| 德保县| 大同市| 华池县| 宣恩县| 交口县| 紫金县| 大洼县| 江达县| 青田县| 荣昌县| 阿拉尔市| 周宁县| 兴山县| 靖宇县| 宁德市| 本溪市|