我需要在ios中播放振动小于0.25秒,振动的顺序是这样的
1 次振动 0.25 秒,然后 3 次振动 0.15 秒,此循环将持续有限的时间,例如 2 或 3 分钟。这里还需要准确性意味着每次振动都必须在准确的时间开始
现在当我播放振动时,它每秒播放一次
-(IBAction)onBtnVibrateClickedid)sender {
[self.view endEditing:YES];
[myTimer invalidate];
if(_txt_VibrationPerMinute.text.length == 0){
_txt_VibrationPerMinute.text = @"10";
}
myTimer = [NSTimer scheduledTimerWithTimeInterval:60/[_txt_VibrationPerMinute.text intValue]
target:self
selectorselector(targetMethod
userInfo:nil
repeats:YES];
}
- (IBAction)obBtnStopVibrationClickedid)sender {
[myTimer invalidate];
}
-(void)targetMethodNSTimer *)timer {
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
Best Answer-推荐答案 strong>
是的,你可以使用这样的东西
FOUNDATION_EXTERN void AudioServicesPlaySystemSoundWithVibration(UInt32 inSystemSoundID,id arg,NSDictionary* vibratePattern);
void vibrate(float durationInSeconds, float intensivity, long count)
{
NSMutableDictionary* dict = [NSMutableDictionary dictionary];
NSMutableArray* arr = [NSMutableArray array];
for (long i = count; i--;)
{
[arr addObject:[NSNumber numberWithBool:YES]]; //vibrate
[arr addObject:[NSNumber numberWithInt:durationInSeconds*1000]];
[arr addObject:[NSNumber numberWithBool:NO]]; //stop
[arr addObject:[NSNumber numberWithInt:durationInSeconds*1000]];
}
[dict setObject:arr forKey"VibePattern"];
[dict setObject:[NSNumber numberWithFloat:intensivity] forKey"Intensity"];
AudioServicesPlaySystemSoundWithVibration(4095,nil,dict);
}
关于ios - 是否可以在objc中的ios中播放小于0.25秒的振动,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/40930556/
|