希望有人可以帮助解决这个问题。我正在尝试使用 UISlider 更改 CA 子层中的值。已经研究了几天,但似乎无法弄清楚。相机运行良好,滑块正在移动,但某处缺少连接..!
附言。对此相对较新,因此将不胜感激分步建议:-)
谢谢!
.h 文件:
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import <QuartzCore/QuartzCore.h>
@interface AVViewController : UIViewController{
IBOutlet UISlider *mySlider;
}
@property (nonatomic, retain) IBOutlet UISlider*mySlider;
- (IBAction)adjustValue:(id)sender;
@end
来自@implementation 行的.m 文件:
@implementation AVViewController
@synthesize mySlider;
- (IBAction)adjustValue:(UISlider *)sender {
float value = [(UISlider *)sender value];
if (value <0) value = 0;
if (value >0) value = 1;
mySlider.value = value;
}
- (void)viewDidLoad
{
[super viewDidLoad];
AVCaptureSession *session = [[AVCaptureSession alloc] init];
[session setSessionPreset:AVCaptureSessionPresetHigh];
NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
AVCaptureDevice *frontCamera = nil;
for (AVCaptureDevice *device in devices) {
if (device.position == AVCaptureDevicePositionFront) {
frontCamera = device;
break;
}
}
NSError *error = nil;
AVCaptureDevice *input = [AVCaptureDeviceInput deviceInputWithDevice:frontCamera error:&error];
[session addInput:input];
AVCaptureVideoPreviewLayer *previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
[previewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
CALayer *rootLayer = [[self view] layer];
[rootLayer setMasksToBounds:YES];
[previewLayer setFrame:CGRectMake(15, 15, 290 , 350)];
previewLayer.cornerRadius = 100.0;
[rootLayer insertSublayer:previewLayer atIndex:0];
CALayer *sublayer = [CALayer layer];
sublayer.frame = CGRectMake (15,15,previewLayer.bounds.size.width,previewLayer.bounds.size.height);
//VALUES TO BE ADJUSTED WITH UI SLIDER
sublayer.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:mySlider.value].CGColor;
[self.view.layer addSublayer:sublayer];
[session startRunning];
}