ios實現微信搖一搖功能 – iPhone手機開發 iPhone軟體開發教學課程

微信搖一搖功能大傢想必用過~ ios SDK幫我們完成瞭所有功作,我們隻需要添加相應的邏輯即可

下面貼出實現代碼(在對應的ViewController中添加如下代碼):

 

 

 

#pragma mark - motion refresh
- (BOOL)canBecomeFirstResponder {
    return YES;
}

- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
    NSLog(@開始搖動);
    AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);//振動效果
}

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
    NSLog(@結束搖動);
}

- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event {
    NSLog(@取消);
}

其中下面代碼是為瞭在搖一搖開始時添加振動效果,需要加入#import

AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

 

 

 

You May Also Like