我需要在ios中播放振动少于0.25秒,振动的顺序将是

1次振动0.25秒,然后3次振动0.15秒,此循环将持续有限的时间,例如2或3分钟。这里也需要精度,这意味着每个振动必须在准确的时间开始

现在,当我演奏振动时,它每秒精确播放一次

-(IBAction)onBtnVibrateClicked:(id)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
                                   selector:@selector(targetMethod:)
                                   userInfo:nil
                                    repeats:YES];
}

- (IBAction)obBtnStopVibrationClicked:(id)sender {

    [myTimer invalidate];


}

-(void)targetMethod:(NSTimer *)timer {
    AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}

最佳答案

是的,您可以使用类似这样的东西

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/

10-12 05:32