I started messing around with the UIProgessbar and then I started having issues with it not updating the view.
Here is my code in view did load:
progressViewBorder = [[UIView alloc] initWithFrame:CGRectMake(0.0f,
cameraBarOverlay.frame.size.height + cameraBarOverlay.frame.origin.y,
self.view.frame.size.width,
10.0f)];
[progressViewBorder setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"progress_bg"]]];
progressView = [[UIProgressView alloc] init];
CGAffineTransform transform = CGAffineTransformMakeScale(1.0f, 5.0f);
progressView.transform = transform;
[progressView setFrame: CGRectMake(0.0f,5.0f,progressViewBorder.frame.size.width,1.0f)];
[progressView setProgressTintColor:[UIColor whiteColor]];
[progressView setUserInteractionEnabled:NO];
[progressView setProgress: 0.0f];
[progressView setProgressViewStyle:UIProgressViewStyleBar];
[progressView setTrackTintColor:[UIColor whiteColor]];
[progressViewBorder setHidden:YES];
[progressViewBorder addSubview:progressView];
[self.view addSubview:progressViewBorder];
Here is my updating code:
- (void)startMovieRecording:(id)sender {
[[self recordButton] setEnabled:NO];
CMTime maxDuration = CMTimeMakeWithSeconds(15, 50);
[[self movieFileOutput] setMaxRecordedDuration:maxDuration];
dispatch_async([self sessionQueue], ^{
if (![[self movieFileOutput] isRecording]) {
[self setLockInterfaceRotation:YES];
if ([[UIDevice currentDevice] isMultitaskingSupported]) {
[self setBackgroundRecordingID:[[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:nil]];
}
// Update the orientation on the movie file output video connection before starting recording.
[[[self movieFileOutput] connectionWithMediaType:AVMediaTypeVideo] setVideoOrientation:[[(AVCaptureVideoPreviewLayer *)[self previewLayer] connection] videoOrientation]];
// Turning OFF flash for video recording
[FTCamViewController setFlashMode:AVCaptureFlashModeOff forDevice:[[self videoDeviceInput] device]];
[toggleFlash setImage:[UIImage imageNamed:[flashImages objectAtIndex:2]] forState:UIControlStateNormal];
currentFlashMode = [flashImages objectAtIndex:2];
// Start recording to a temporary file.
NSString *outputFilePath = [NSTemporaryDirectory() stringByAppendingPathComponent:[@"movie" stringByAppendingPathExtension:@"mov"]];
[[self movieFileOutput] startRecordingToOutputFileURL:[NSURL fileURLWithPath:outputFilePath] recordingDelegate:self];
while ([[self movieFileOutput] isRecording]) {
double duration = CMTimeGetSeconds([[self movieFileOutput] recordedDuration]);
double time = CMTimeGetSeconds([[self movieFileOutput] maxRecordedDuration]);
CGFloat progress = (CGFloat) (duration / time);
dispatch_async(dispatch_get_main_queue(), ^{
[progressView setProgress:progress animated:YES];
});
}
} else {
[[self movieFileOutput] stopRecording];
}
});
}
Can anyone tell why this wouldn't be updating?
Well this is really bad but it turns out that I had the tint color and progress tint color set to the same.. whiteColor. This was causing the display to act very strange.
Here is what solved it for me.
[self.progressView setProgressTintColor:[UIColor whiteColor]];
[self.progressView setUserInteractionEnabled:NO];
[self.progressView setProgressViewStyle:UIProgressViewStyleDefault];
[self.progressView setTrackTintColor:[UIColor clearColor]];
From looking around for possible solutions I updated my while loop to this:
while ([[self movieFileOutput] isRecording]) {
double duration = CMTimeGetSeconds([[self movieFileOutput] recordedDuration]);
double time = CMTimeGetSeconds([[self movieFileOutput] maxRecordedDuration]);
CGFloat progress = (CGFloat) (duration / time);
[self performSelectorInBackground:@selector(updateProgress:) withObject:[NSNumber numberWithFloat:progress]];
}
And my selector does the updating.
- (void)updateProgress:(NSNumber *)progress {
[self.progressView setProgress:[progress floatValue] animated:YES];
}