如何在 iOS 上设置两个按钮来打开/关闭振动?
这就是我想要做的:
@property (nonatomic) BOOL vibeIsOn;
- (IBAction)startVibrating:(id)sender {
dispatch_queue_t vibeQueue = dispatch_queue_create("vibe", NULL);
dispatch_sync(vibeQueue, ^{
for (;!self.vibeIsOn;)
{
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
});
dispatch_release(vibeQueue);}
- (IBAction)stopVibrating:(id)sender {
self.vibeIsOn = YES;
AudioServicesRemoveSystemSoundCompletion(kSystemSoundID_Vibrate);}
不幸的是,当我按下“凝视振动”按钮时,它无法跳出for循环,但我确实将for循环放在了一个线程中,对吧?
帮助!!!这段代码有什么问题吗?