我开始搞乱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];
}
});
}
有谁可以告诉为什么这不会更新?
答案 0 :(得分:1)
嗯,这真的很糟糕,但事实证明我将色调颜色和进度色调设置为相同的颜色.. whiteColor。这导致显示器非常奇怪。
这就是为我解决的问题。
[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];
}
答案 1 :(得分:-1)
将您的while代码放在一个单独的方法中。使用
调用此方法[self performSelectorOnBackgroundThread....]
添加一个方法来更新进度条,并通过
从while方法中获取此方法[self performSelectorOnMainThread....]
克劳斯