Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/100.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 手电筒摇动打开_Iphone_Ios_Objective C_Uiviewcontroller - Fatal编程技术网

Iphone 手电筒摇动打开

Iphone 手电筒摇动打开,iphone,ios,objective-c,uiviewcontroller,Iphone,Ios,Objective C,Uiviewcontroller,我在xcode上有一个手电筒项目,但我不知道如何添加亮度控制。我有一些按钮隐藏在手电筒的打开和关闭部分,我使用ImageView显示预渲染的图像。我将我的代码张贴在下面,所有的帮助都将被感谢 Viewcontroller.h- is basically the initializations of the buttons, IBActions, IBOutlets and Properties ViewController.m #import "ViewController.h"

我在xcode上有一个手电筒项目,但我不知道如何添加亮度控制。我有一些按钮隐藏在手电筒的打开和关闭部分,我使用ImageView显示预渲染的图像。我将我的代码张贴在下面,所有的帮助都将被感谢

Viewcontroller.h-  
is basically the initializations of the buttons, IBActions, IBOutlets and Properties


ViewController.m



#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

@synthesize offButton,onview,onButton,offview,slider;

-(IBAction)torchon:(id)sender
{

    onButton.hidden=YES;
    offButton.hidden=NO;
    onview.hidden=NO;
    offview.hidden=YES;


    AVCaptureDevice *device=[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    if([device isTorchAvailable]&&[device isTorchModeSupported:AVCaptureTorchModeOn])
    {
        BOOL sucessful=[device  lockForConfiguration:nil];
        if(sucessful)
        {
            [device  setTorchModeOnWithLevel:slider.value error:NULL];

            [device  unlockForConfiguration];
        }
    }
}

-(IBAction)torchoff:(id)sender
{
    AVCaptureDevice *flashlight=[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    if([flashlight isTorchAvailable]&&[flashlight isTorchModeSupported:AVCaptureTorchModeOn])
    {
        BOOL sucessful=[flashlight lockForConfiguration:nil];
        if(sucessful)
        {
            [flashlight setTorchMode:AVCaptureTorchModeOff];

            [flashlight unlockForConfiguration];

        }
    }

    onButton.hidden=NO;
    offButton.hidden=YES;
    onview.hidden=YES;
    offview.hidden=NO;
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    onButton.hidden=YES;
    offButton.hidden=NO;
    onview.hidden=NO;
    offview.hidden=YES;
    AVCaptureDevice *device =[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    if([device  isTorchAvailable]&&[device  isTorchModeSupported:AVCaptureTorchModeOn])
    {
        BOOL sucessful=[device  lockForConfiguration:nil];
        if(sucessful)
        {
            [device  setTorchMode:AVCaptureTorchModeOn];

            [device  unlockForConfiguration];
        }
    }
}
-(IBAction)slideing:(id)sender
{
    slider.maximumValue = 1.0f;
    slider.minimumValue = 0.0f;
    [slider setContinuous:YES];
    [slider addTarget:self action:@selector(sliderDidChange:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:slider];
    AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    [device lockForConfiguration:nil];
    [device setTorchModeOnWithLevel:slider.value error:NULL];
    [device unlockForConfiguration];


}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated

}
@end



and nothing in appdelegate.m and appdelegate.h

i have created my objects like a slider, and button as well as the image views in a storyboard and have linked them to my code. I've used IBAction functions and have used interface builder a bit as well. As i said before, i cant figure out how to add a shake to switch on and off feature. Any help is appreciated!

好主意,时机不对。iOS7将有一个内置的手电筒,所以你可能需要考虑其他的东西来构建。无论如何谢谢你