iOS的UIProgressView栏没有更新,有人可以告诉我原因吗?

拉兹海龟

我开始弄乱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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

TextGeometry没有显示,有人可以告诉我为什么吗?

有人可以告诉我一个好的依赖矩阵是什么样子并指定原因吗?

有人可以告诉我我的代码有什么问题吗?[Python 2.7.1]

有人可以告诉我我的代码有什么问题吗?

有人可以告诉我是否可以从我的CLinfo日志中执行OpenCL吗?

有人可以告诉我这段代码有什么问题吗

有人可以告诉我这张图片有什么问题吗?

有人可以告诉我此python代码有什么问题吗?

有人可以告诉我为什么我的actionListener for循环不起作用吗?

有人可以告诉我我的Type或linq查询出了什么问题吗

我是React的新手,有人可以告诉我为什么会这样吗?

有人可以告诉我为什么我的if / else陈述不起作用吗?

有人可以告诉我svg中的<g>和</ g>吗?

Java的新手。有人可以告诉我这是否是正确的写作方式吗?

有人可以告诉我如何在DIV中正确插入文本吗?

有人可以告诉我点击网页上链接的Selense命令吗

有人可以告诉我一个简单的PagerSlidingTabStrip工作实现吗?

有人可以告诉我此python代码在哪里出错吗?

有人可以告诉我最后一个循环在做什么吗?

有人可以告诉我如何简化此代码吗?

有人可以告诉我如何计算select prepare语句的返回值吗?

有人可以告诉我代码中的错误吗?

有人可以告诉我这个mips问题是什么意思吗?

有人可以告诉我为什么a:hover不起作用吗?

如何打印此图案?有人可以告诉我条件(如果声明)吗?

有人可以告诉我DateTimeZone :: getOffset PHP函数如何工作吗?

有人可以告诉我这是什么类型的吗?

有人可以告诉我这个正则表达式吗?

有人可以告诉我这个sql代码中的错误吗?