gpt4 book ai didi

iphone - 如何防止我的 iPhone 4 手电筒应用程序在关闭时闪烁?

转载 作者:行者123 更新时间:2023-11-28 17:43:52 25 4
gpt4 key购买 nike

我正在玩一个简单的小手电筒应用程序,当您在我的 View 上按下按钮时,它会打开和关闭 LED 闪光灯。

它工作得很好,但是当我关闭闪光灯时,它会在关闭前闪烁一次。知道是什么导致了这种行为吗?

相关代码如下:

//
// No_Frills_FlashlightViewController.m
// No Frills Flashlight
//
// Created by Terry Donaghe on 8/9/11.
// Copyright 2011 Tilde Projects. All rights reserved.
//

#import "No_Frills_FlashlightViewController.h"

@implementation No_Frills_FlashlightViewController

@synthesize AVSession;


- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
}
*/

- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (IBAction)TurnOnLight:(id)sender {
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

AVSession = [[AVCaptureSession alloc] init];

AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:nil];
[AVSession addInput:input];

AVCaptureVideoDataOutput *output = [[AVCaptureVideoDataOutput alloc] init];
[AVSession addOutput:output];

[AVSession beginConfiguration];
[device lockForConfiguration:nil];

[device setTorchMode:AVCaptureTorchModeOn];
[device setFlashMode:AVCaptureFlashModeOn];

[device unlockForConfiguration];
[AVSession commitConfiguration];

[AVSession startRunning];

[self setAVSession:AVSession];

[output release];
}

- (IBAction)TurnOffLight:(id)sender {

[AVSession stopRunning];
[AVSession release];
AVSession = nil;
}

- (IBAction)DoNothing:(id)sender {
}
@end

AVSession 只是类级别的 AVCaptureSession 变量。

是的,这是我刚刚在 Internet 上找到的代码。我只是在玩,并试图解决问题。

最佳答案

我弄明白是怎么回事了,跟代码一点关系也没有。 :) ID10T 错误。

我复制了“打开”按钮来创建“关闭”按钮。由于复制,我忘记取消“关闭”按钮与 TurnOnLight 方法的连接。

我只是删除了该连接,现在该应用程序可以完美运行了! :)

经验教训:有时问题不在于您的源代码。 :D

关于iphone - 如何防止我的 iPhone 4 手电筒应用程序在关闭时闪烁?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7006161/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com