如何設置兩個按鈕來打開/關閉iOS上的振動?如何設置兩個按鈕來打開/關閉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循環在一個線程中,對嗎?
幫助!!!這段代碼有什麼問題嗎?
什麼叫「'stopVibrating'」?與「'startVibrating'」相同的按鈕? – 2012-08-04 02:40:32
stopVibrating和startVibrating都是視圖上的按鈕 – 2012-08-04 03:15:27