中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

iOS實現微信搖一搖功能

發布時間:2020-10-12 11:53:46 來源:腳本之家 閱讀:237 作者:獅兄 欄目:移動開發

一、描述

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

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.
}
*/

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持億速云。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

南丰县| 昭平县| 西城区| 准格尔旗| 开原市| 开鲁县| 白河县| 晴隆县| 靖江市| 瑞丽市| 石城县| 宜宾市| 昔阳县| 德安县| 武定县| 三都| 长兴县| 遂川县| 师宗县| 吐鲁番市| 绥芬河市| 商丘市| 阳山县| 江津市| 阿瓦提县| 托克逊县| 忻州市| 阜康市| 湟中县| 白玉县| 梅州市| 三明市| 阿拉善右旗| 孙吴县| 临夏县| 龙胜| 从化市| 驻马店市| 吕梁市| 商洛市| 建湖县|