我有两个视图控制器。一和二。
- 在 oneViewController 上,有一个使用 Storyboard 调用 TwoViewController 的按钮 - 工作正常
- 在 TwoViewController 上有一个按钮,可以使用按钮(Listen Button)读取一些文本 - 工作正常
- TwoViewController 上有返回按钮,可将您带回 oneViewController。
问题:
如果两次单击“听”按钮并按下“返回”按钮,则视图控制器会从“二”变为“一”,但语音仍在后台进行。有人可以帮忙阻止演讲吗?
TwoViewController 上的代码:
AVSpeechSynthesizer *synth;
-(IBAction) Back:(id)sender
{
[_synth stopSpeakingAtBoundary: AVSpeechBoundaryImmediate]; --not working
[self dismissViewControllerAnimated:YES completion:nil]; - working fine.
}
-(void) viewDidDisappear:(BOOL)animated
{
[_synth stopSpeakingAtBoundary:AVSpeechBoundaryImmediate]; --not working
[self dismissViewControllerAnimated:YES completion:nil];
}
-(IBAction)listenButton:(id)sender
{
AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:@"I am running a test."];
[utterance setRate:0.18f];
_synth=[[AVSpeechSynthesizer alloc] init];
[_synth speakUtterance:utterance];
}
注意:如果单击“收听”按钮一次,然后单击“返回”按钮,则不会发生此问题。仅当多次单击“收听”按钮然后单击“返回”按钮时才会出现问题。