我开始弄乱UIProgessbar,然后开始遇到关于不更新视图的问题。
这是我的代码,因为它确实加载了:
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];
这是我的更新代码:
- (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];
}
});
}
谁能说出为什么不更新呢?
好吧,这确实很糟糕,但是事实证明我将着色颜色和进度着色设置为相同的颜色。这导致显示器表现得很奇怪。
这是为我解决的问题。
[self.progressView setProgressTintColor:[UIColor whiteColor]];
[self.progressView setUserInteractionEnabled:NO];
[self.progressView setProgressViewStyle:UIProgressViewStyleDefault];
[self.progressView setTrackTintColor:[UIColor clearColor]];
通过寻找可能的解决方案,我将while循环更新为:
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]];
}
然后我的选择器进行更新。
- (void)updateProgress:(NSNumber *)progress {
[self.progressView setProgress:[progress floatValue] animated:YES];
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句