是否可以在物体中以小于0.25秒的速度播放一次振动

时间:2016-12-02 10:56:31

标签: ios objective-c iphone

我需要在ios中发挥不到0.25秒的振动,振动的顺序就像

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

现在,当我发挥振动时,它每秒只播放一次

OPTIONS

1 个答案:

答案 0 :(得分:0)

是的,你可以使用这样的东西

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);
}