iOS,위 챗 흔 들 기 기능 구현

설명
인 터 페 이 스 를 만들어 서 위 챗 을 본 떠 흔 들 어 인 터 페 이 스 를 가 져 와 서명 기능 을 해 야 합 니 다.
먼저 다음 과 같은 몇 가 지 를 명 확 히 한다.
1.진동 이 필요 합 니 다.
2.소리 가 필요 해 요.(mp3 사 운 드 준비)
2.여기 바로 코드 붙 이기

/ 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.
}
*/
이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기