Разгледах няколко публикации, включително [тази].1 Точно това искам да направя, но не мога да го накарам да работи.
Искам да покажа на потребителя, че е натиснал бутон за запис и че ще трябва да го натисне отново, за да спре записа.
Досега кодът за метода за стартиране на запис изглежда така:
NSLog(@"DetailVC - recordAudio - soundFilePath is %@", soundFile);
[audioRecorder prepareToRecord];
recording = YES;
NSLog(@"start recording");
NSLog(@"1");
//[autoCog startAnimating];
[audioRecorder recordForDuration:120];
recording = NO;
//Start a timer to animate the record images
if (recording == YES) {
toggle = FALSE;
timer = [NSTimer scheduledTimerWithTimeInterval: 2.0
target: self
selector: @selector(toggleButtonImage:)
userInfo: nil
repeats: YES];
//UIImage *changeImage = [UIImage imageNamed:stopButtonFile];
//[recordButton setImage:changeImage forState:UIControlStateNormal];
//[timer invalidate];
//timer = nil;
NSLog(@"2");
}
и методът toggleButton изглежда така:
- (void)toggleButtonImage:(NSTimer*)timer
{
NSLog(@"%s", __FUNCTION__);
if(toggle)
{
NSLog(@"1");
/*
[UIView beginAnimations];
recordButton.opacity = 0.0;
[recordButton setAnimationDuration: 1.5];
[recordButton commitAnimations];
[recordButton setImage:[UIImage imageNamed:@"record.png"] forState: UIControlStateNormal];
*/
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; //delete "EaseOut", then push ESC to check out other animation styles
[UIView setAnimationDuration: 0.5];//how long the animation will take
[UIView setAnimationDelegate: self];
recordButton.alpha = 1.0; //1.0 to make it visible or 0.0 to make it invisible
[UIView commitAnimations];
}
else
{
NSLog(@"2");
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; //delete "EaseOut", then push ESC to check out other animation styles
[UIView setAnimationDuration: 0.5];//how long the animation will take
[UIView setAnimationDelegate: self];
recordButton.alpha = 0.0; //1.0 to make it visible or 0.0 to make it invisible
[UIView commitAnimations];
//[recordButton setImage:[UIImage imageNamed:@"stopGrey.png"] forState: UIControlStateNormal];
}
toggle = !toggle;
}
Виждам регистрационните файлове, показващи, че цикълът се повтаря, но:
- изображенията не се сменят и
- операцията не се изпълнява паралелно с метода на запис.
Ще се радвам на всякакви идеи как да продължа.