<small id='w70Qu'></small><noframes id='w70Qu'>

<i id='w70Qu'><tr id='w70Qu'><dt id='w70Qu'><q id='w70Qu'><span id='w70Qu'><b id='w70Qu'><form id='w70Qu'><ins id='w70Qu'></ins><ul id='w70Qu'></ul><sub id='w70Qu'></sub></form><legend id='w70Qu'></legend><bdo id='w70Qu'><pre id='w70Qu'><center id='w70Qu'></center></pre></bdo></b><th id='w70Qu'></th></span></q></dt></tr></i><div id='w70Qu'><tfoot id='w70Qu'></tfoot><dl id='w70Qu'><fieldset id='w70Qu'></fieldset></dl></div>
  • <tfoot id='w70Qu'></tfoot>

    1. <legend id='w70Qu'><style id='w70Qu'><dir id='w70Qu'><q id='w70Qu'></q></dir></style></legend>
        <bdo id='w70Qu'></bdo><ul id='w70Qu'></ul>
      1. 如何让 iPhone 4 LED 灯瞬间发光?

        How can I make the iPhone 4 LED light fire instantly?(如何让 iPhone 4 LED 灯瞬间发光?)

          <bdo id='WPm1j'></bdo><ul id='WPm1j'></ul>

                <tbody id='WPm1j'></tbody>
            • <small id='WPm1j'></small><noframes id='WPm1j'>

              <tfoot id='WPm1j'></tfoot>

                <i id='WPm1j'><tr id='WPm1j'><dt id='WPm1j'><q id='WPm1j'><span id='WPm1j'><b id='WPm1j'><form id='WPm1j'><ins id='WPm1j'></ins><ul id='WPm1j'></ul><sub id='WPm1j'></sub></form><legend id='WPm1j'></legend><bdo id='WPm1j'><pre id='WPm1j'><center id='WPm1j'></center></pre></bdo></b><th id='WPm1j'></th></span></q></dt></tr></i><div id='WPm1j'><tfoot id='WPm1j'></tfoot><dl id='WPm1j'><fieldset id='WPm1j'></fieldset></dl></div>
                  <legend id='WPm1j'><style id='WPm1j'><dir id='WPm1j'><q id='WPm1j'></q></dir></style></legend>
                  本文介绍了如何让 iPhone 4 LED 灯瞬间发光?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我目前正在使用下面的代码来打开和关闭我的 iPhone 4 LED 灯,效果很好,但唯一的问题是每次打开 LED 时都会有轻微的延迟.但是它会立即关闭.我需要它立即触发以实现类似频闪的功能,因为它更方便.

                  I'm currently using the below code to turn on and off my iPhone 4 LED light and it's working great, but the only problem is that every time I turn the LED on there is a slight delay. However it turns off instantly. I need it to fire instantly to implement a strobe like feature, and because it's just more convenient.

                  我注意到,在 Apple 的相机应用程序和许多其他应用程序中,当您按下电源按钮时,LED 会立即打开和关闭.

                  I've noticed that in Apple's camera app and many other apps that the LED turns on and off instantaneously when you hit the power button.

                  我尝试将会话"和设备"之类的一些对象作为实例变量添加到我的视图控制器中,以便让 iPhone 在加载时创建这些对象,但是我没有获得任何运气它工作.

                  I've tried adding some of the objects like "session" and "device" as instance variables to my view controller in order to have the iPhone create those objects at load time, however I haven't had any luck in getting it to work.

                  我也尝试查看苹果的 WWDC 示例代码,但我似乎无法破译他们的复杂代码.有人可以帮我弄清楚我已经尝试了大约 4 天来让它工作.

                  I've also tried looking at apples WWDC sample code but I just can't seem to decipher their complex code. Can someone please help me figure this out i've been trying for about 4 days to get this to work.

                  #import <UIKit/UIKit.h>
                  #import <AVFoundation/AVFoundation.h>
                  
                  @interface FlashlightViewController : UIViewController {
                  
                      AVCaptureSession *torchSession;
                  }
                  
                  @property (nonatomic, retain) AVCaptureSession * torchSession;
                  
                  - (void) toggleTorch;
                  
                  @end
                  

                  .m

                  #import "FlashlightViewController.h"
                  
                  @implementation FlashlightViewController
                  
                  @synthesize torchSession;
                  
                  - (void)dealloc 
                  {
                      [torchSession release];
                      [super dealloc];
                  }
                  
                  - (void)viewDidLoad 
                  {
                      [self toggleTorch];
                      [super viewDidLoad];
                  }
                  
                  - (void) toggleTorch 
                  {
                      AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
                  
                      if ([device hasTorch] && [device hasFlash])
                      {
                          if (device.torchMode == AVCaptureTorchModeOff) 
                          {
                              NSLog(@"It's currently off.. turning on now.");
                  
                              AVCaptureDeviceInput *flashInput = [AVCaptureDeviceInput deviceInputWithDevice:device error: nil];
                              AVCaptureVideoDataOutput *output = [[AVCaptureVideoDataOutput alloc] init];
                  
                              AVCaptureSession *session = [[AVCaptureSession alloc] init];
                  
                              [session beginConfiguration];
                              [device lockForConfiguration:nil];
                  
                              [device setTorchMode:AVCaptureTorchModeOn];
                              [device setFlashMode:AVCaptureFlashModeOn];
                  
                              [session addInput:flashInput];
                              [session addOutput:output];
                  
                              [device unlockForConfiguration];
                  
                              [output release];
                  
                              [session commitConfiguration];
                              [session startRunning];
                  
                              [self setTorchSession:session];
                              [session release];
                          }
                          else {
                  
                              NSLog(@"It's currently on.. turning off now.");
                              [torchSession stopRunning];
                          }
                      }
                  }
                  

                  推荐答案

                  在你想要打开闪光灯 LED 之前,在应用程序初始化或查看加载期间,做所有的事情(所有会话和设备配置的东西).

                  Do everything (all the session and device configuration stuff) except the flash configuration block before you want to turn the flash LED on, during app init or view load.

                  然后,当您想打开 LED 时,只需打开手电筒模式即可.比如:

                  Then just set torch mode on when you want to turn the LED on. Something like:

                  [self.myDevice lockForConfiguration:nil];
                  [self.myDevice setTorchMode:AVCaptureTorchModeOn];
                  [self.myDevice setFlashMode:AVCaptureFlashModeOn];
                  [self.myDevice unlockForConfiguration];
                  

                  确保 myDevice 在您的初始化过程中是正确配置的属性.

                  Make sure that myDevice is a properly configured property during your init.

                  这篇关于如何让 iPhone 4 LED 灯瞬间发光?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  EAAccessory/EASession teardown during background(EAAccessory/EASession 在后台拆除)
                  Getting an NSArray of a single attribute from an NSArray(从 NSArray 获取单个属性的 NSArray)
                  ImageIO: lt;ERRORgt; JPEG Corrupt JPEG data: premature end of data segment iphone - how to catch this?(ImageIO:lt;错误gt;JPEG 损坏的 JPEG 数据:iphone 数据段过早结束 - 如何捕捉到这个?)
                  Xcode iOS organizer submit to app store yields quot;The archive is invalidquot; error(Xcode iOS 管理器提交到应用商店产生“存档无效;错误)
                  MFMessageComposeViewController alloc returns nil(MFMessageComposeViewController alloc 返回 nil)
                  How to add and get the values from .plist in iOS(如何在 iOS 中从 .plist 添加和获取值)

                          <bdo id='skEjW'></bdo><ul id='skEjW'></ul>

                          <small id='skEjW'></small><noframes id='skEjW'>

                          1. <tfoot id='skEjW'></tfoot><legend id='skEjW'><style id='skEjW'><dir id='skEjW'><q id='skEjW'></q></dir></style></legend>
                            <i id='skEjW'><tr id='skEjW'><dt id='skEjW'><q id='skEjW'><span id='skEjW'><b id='skEjW'><form id='skEjW'><ins id='skEjW'></ins><ul id='skEjW'></ul><sub id='skEjW'></sub></form><legend id='skEjW'></legend><bdo id='skEjW'><pre id='skEjW'><center id='skEjW'></center></pre></bdo></b><th id='skEjW'></th></span></q></dt></tr></i><div id='skEjW'><tfoot id='skEjW'></tfoot><dl id='skEjW'><fieldset id='skEjW'></fieldset></dl></div>
                              <tbody id='skEjW'></tbody>