我正在开发一款具有视频功能的相机应用。我想要用户按下的按钮开始录制,然后停止录制。这工作正常。但是,我想在按下按钮时将recordButton
的alpha增加到1.0。这可以正常工作,但当再次按下它以停止记录时,alpha保持为1.0。停止录制的if...else
语句应该触发[self.recordButton setAlpha:0.50]
,但由于某些原因,除了录制正确停止之外没有任何反应。任何澄清将不胜感激。
- (IBAction)toggleMovieRecording:(id)sender
{
[[self recordButton] setEnabled:NO];
dispatch_async([self sessionQueue], ^{
if (![[self movieFileOutput] isRecording])
{
[self setLockInterfaceRotation:YES];
[self.recordButton setAlpha:1.0];
if ([[UIDevice currentDevice] isMultitaskingSupported])
{
// Setup background task. This is needed because the captureOutput:didFinishRecordingToOutputFileAtURL: callback is not received until the app returns to the foreground unless you request background execution time. This also ensures that there will be time to write the file to the assets library when the app is backgrounded. To conclude this background execution, -endBackgroundTask is called in -recorder:recordingDidFinishToOutputFileURL:error: after the recorded file has been saved.
[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 previewView] layer] connection] videoOrientation]];
// Turn OFF flash for video recording
[AAPLCameraViewController setFlashMode:AVCaptureFlashModeOff forDevice:[self videoDevice]];
// Start recording to a temporary file.
NSString *outputFilePath = [NSTemporaryDirectory() stringByAppendingPathComponent:[@"movie" stringByAppendingPathExtension:@"mov"]];
[[self movieFileOutput] startRecordingToOutputFileURL:[NSURL fileURLWithPath:outputFilePath] recordingDelegate:self];
}
else
{
[[self movieFileOutput] stopRecording];
[self.recordButton setAlpha:0.50];
}
});
}
答案 0 :(得分:0)
您必须确保必须在主队列上完成与UI相关的任何操作。检查这个答案 iPhone - Grand Central Dispatch main thread
确保在设置alpha时添加此块。
dispatch_async(dispatch_get_main_queue(), ^{
[self.recordButton setAlpha:0.50];
});
如果有效,请告诉我。