Ios 发生touchUpInside事件后setAlpha未触发

Ios 发生touchUpInside事件后setAlpha未触发,ios,objective-c,xcode,cocoa-touch,Ios,Objective C,Xcode,Cocoa Touch,我正在开发一个具有视频功能的摄像头应用程序。我希望用户按下按钮开始录制,然后停止录制。这工作正常。但是,我想在按下按钮时将recordButton的alpha值提高到1.0。这可以正常工作,但当再次按下以停止记录时,alpha保持在1.0。停止录制的if…else语句应触发[self.recordButton setAlpha:0.50],但由于某种原因,除了正确停止录制外,什么也不会发生。如有任何澄清,将不胜感激 - (IBAction)toggleMovieRecording:(id)sen

我正在开发一个具有视频功能的摄像头应用程序。我希望用户按下按钮开始录制,然后停止录制。这工作正常。但是,我想在按下按钮时将
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];
    }
});
}

您必须确保必须在主队列上完成与UI相关的任何操作。检查这个答案

确保围绕设置alpha添加此块

dispatch_async(dispatch_get_main_queue(), ^{
            [self.recordButton setAlpha:0.50];
        }); 

让我知道这是否有效。

太好了!快乐编码!