iOS 위챗 모방 흔들기 기능 구현

6806 단어 iOS
iOS 위챗 모방 흔들기 기능 구현
1. 설명은 하나의 인터페이스를 만들어야 한다. 위챗을 본떠서 흔들고 인터페이스를 가져와 출석 기능을 한다.먼저 다음과 같은 몇 가지를 명확히 한다. 1. 진동이 필요하다.2. 소리가 필요합니다.(mp3 사운드 준비) 2. 여기에 코드를 직접 붙인다.
/  Created by     on 16/7/29.
//  Copyright © 2016     . All rights reserved.
//

#import "SignBoardViewController.h"
#import 
#import 
#import 
@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 *)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.
}
*/

좋은 웹페이지 즐겨찾기