当前位置: 移动技术网 > IT编程>移动开发>IOS > iOS仿微信摇一摇功能

iOS仿微信摇一摇功能

2019年07月24日  | 移动技术网IT编程  | 我要评论

宝宝干咳是什么原因,一起游侠,东流影院限制片

ios仿照微信摇一摇功能实现

一、描述

需要做一个界面,仿照微信摇一摇,获取接口进行签到功能。
首先明确以下几点:
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.
}
*/

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网