Я просмотрел несколько постов, включая [этот]. 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;
}
Я вижу журналы, показывающие, что цикл повторяется, но:
- изображения не переключаются, а
- операция не выполняется параллельно с методом записи.
Буду признателен за любые идеи о том, как поступить.