xcode 如何让我的 iPhone 4 手电筒应用程序在关闭时不闪烁?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7006161/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I keep my iPhone 4 flashlight app from blinking when it turns off?
提问by Tad Donaghe
I'm playing around with a simple little flashlight app that turns on and off the LED flash when you press buttons on my view.
我正在玩一个简单的小手电筒应用程序,当你按下我视图上的按钮时,它会打开和关闭 LED 闪光灯。
It works just fine, but when I turn off the flash, it blinks once before turning off. Any ideas what's causing this behavior?
它工作得很好,但是当我关闭闪光灯时,它会在关闭之前闪烁一次。任何想法是什么导致这种行为?
Here's the pertinent code:
这是相关的代码:
//
// 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 is just a class level AVCaptureSession variable.
AVSession 只是一个类级别的 AVCaptureSession 变量。
And yes, this is code I just found on the internets. I'm just playing and trying to figure things out.
是的,这是我刚刚在互联网上找到的代码。我只是在玩游戏并试图解决问题。
采纳答案by Tad Donaghe
I figured out what was going on, and it had nothing to do with the code. :) ID10T error.
我弄清楚发生了什么,这与代码无关。:) ID10T 错误。
I had copied the "Turn On" button to create the "Turn Off" button. I forgot to unwire the "Turn Off" button's connection to the TurnOnLight method that was there due to the copying.
我复制了“打开”按钮来创建“关闭”按钮。由于复制,我忘记断开“关闭”按钮与 TurnOnLight 方法的连接。
I simply removed that connection and now the app works perfectly! :)
我只是删除了该连接,现在该应用程序运行良好!:)
Lesson Learned: Sometimes it's not your source code that's the problem. :D
经验教训:有时问题不在于您的源代码。:D