0

xcode に懐中電灯プロジェクトがありますが、それに輝度制御を追加する方法がわかりません。懐中電灯のオンとオフの部分で非表示になっているボタンがあり、imageviews を使用して事前にレンダリングされた画像を表示しています。以下に私のコードを投稿します。すべての助けに感謝します。

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!
4

0 に答える 0