欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時間:2018年06月25日 14:59:37   作者:獅兄  
這篇文章主要為大家詳細(xì)介紹了iOS實(shí)現(xiàn)微信搖一搖功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下

一、描述

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

1、需要震動。
2、需要聲音。(準(zhǔn)備好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;

  //添加點(diǎn)擊方法
  [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 點(diǎn)擊
- (void)touchesBegan:(nonnull NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event

{
  NSLog(@"點(diǎn)擊,觸摸方法等");
  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)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 詳解IOS判斷當(dāng)前網(wǎng)絡(luò)狀態(tài)的三種方法

    詳解IOS判斷當(dāng)前網(wǎng)絡(luò)狀態(tài)的三種方法

    這篇文章主要介紹了詳解IOS判斷當(dāng)前網(wǎng)絡(luò)狀態(tài)的三種方法,網(wǎng)絡(luò)狀態(tài)是非常重要的知識,感興趣的同學(xué),必須要看一下
    2021-04-04
  • iOS圖片拉伸技巧小結(jié)

    iOS圖片拉伸技巧小結(jié)

    這篇文章主要為大家詳細(xì)介紹了iOS圖片拉伸的技巧,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-01-01
  • iOS如何為圓角添加陰影效果示例代碼

    iOS如何為圓角添加陰影效果示例代碼

    最近一個項(xiàng)目中需要用到投影的效果,還要是圓角,通過查找相關(guān)的資料終于解決了,所以覺著有必要分享出來,下面這篇文章主要給大家介紹了關(guān)于iOS如何為圓角添加陰影效果的相關(guān)資料,需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-10-10
  • iOS CAEmitterLayer實(shí)現(xiàn)粒子發(fā)射動畫效果

    iOS CAEmitterLayer實(shí)現(xiàn)粒子發(fā)射動畫效果

    這篇文章主要為大家詳細(xì)介紹了iOS CAEmitterLayer 實(shí)現(xiàn)粒子發(fā)射動畫效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-06-06
  • iOS中使用JSPatch框架使Objective-C與JavaScript代碼交互

    iOS中使用JSPatch框架使Objective-C與JavaScript代碼交互

    有了JSPatch,我們便可以在iOS App開發(fā)中令JavaScript代碼調(diào)用原生的Objective-C屬性和方法等,下面就來詳細(xì)看一下如何在iOS中使用JSPatch框架使Objective-C與JavaScript代碼交互
    2016-06-06
  • iOS中的AutoLayout使用實(shí)踐總結(jié)

    iOS中的AutoLayout使用實(shí)踐總結(jié)

    在對界面進(jìn)行布局的時候,我們經(jīng)常使用AutoLayout對界面進(jìn)行布局適配。下面這篇文章主要給大家介紹了iOS中AutoLayout使用實(shí)踐的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-12-12
  • iOS長按UIlabel實(shí)現(xiàn)可復(fù)制功能

    iOS長按UIlabel實(shí)現(xiàn)可復(fù)制功能

    在我們?nèi)粘5拈_發(fā)中經(jīng)常會遇到一些小需求,比如需要長按控件來拷貝控件中得內(nèi)容,所以這篇文章跟大家分享下iOS中長按UIlabel實(shí)現(xiàn)可復(fù)制功能的方法,有需要的朋友們可以參考借鑒。
    2016-09-09
  • iOS去除圖片背景顏色的方法

    iOS去除圖片背景顏色的方法

    本篇文章給大家分享一下iOS去除圖片中指定范圍內(nèi)顏色的三種方式,需要的朋友參考學(xué)習(xí)下吧。
    2017-12-12
  • iOS App初次啟動時的用戶引導(dǎo)頁制作實(shí)例分享

    iOS App初次啟動時的用戶引導(dǎo)頁制作實(shí)例分享

    這篇文章主要介紹了iOS App初次啟動時的用戶引導(dǎo)頁制作實(shí)例分享,其中判斷程序是否是第一次或版本更新以后第一次啟動是一個關(guān)鍵點(diǎn),需要的朋友可以參考下
    2016-03-03
  • IOS實(shí)現(xiàn)選擇城市后跳轉(zhuǎn)Tabbar效果

    IOS實(shí)現(xiàn)選擇城市后跳轉(zhuǎn)Tabbar效果

    這篇文章主要為大家詳細(xì)介紹了IOS實(shí)現(xiàn)選擇城市后跳轉(zhuǎn)Tabbar效果的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-07-07

最新評論