Tôi có ứng dụng AV Foundation mô phỏng chụp ảnh (như ứng dụng máy ảnh). Thông thường các công trình sau đây cho tôi, nhưng không phải trong trường hợp này.Mô phỏng đèn flash "chụp ảnh"
Mã này thực thi trong một hành động trong trình điều khiển chế độ xem của tôi. Nó chứa một UIView toàn màn hình duy nhất (videoPreviewLayer) có kèm theo AVCaptureVideoPreviewLayer. Hoạt ảnh thực hiện nhưng không có gì được hiển thị. Cũng lưu ý rằng tôi đang sử dụng ARC, iOS 6, iPhone 4S, iPad3.
// Flash the screen white and fade it out
UIView *flashView = [[UIView alloc] initWithFrame:[[self videoPreviewView] frame]];
[flashView setBackgroundColor:[UIColor whiteColor]];
[[[self view] window] addSubview:flashView];
[UIView animateWithDuration:1.f
animations:^{
[flashView setAlpha:0.f];
}
completion:^(BOOL finished){
[flashView removeFromSuperview];
}
];
Sau đây là cách tôi đính kèm các AVCaptureVideoPreviewLayer:
// Setup our preview layer so that we can display video from the camera
captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.captureSession];
CALayer *viewLayer = videoPreviewView.layer;
viewLayer.masksToBounds = YES;
captureVideoPreviewLayer.frame = videoPreviewView.bounds;
[viewLayer insertSublayer:captureVideoPreviewLayer below:[[viewLayer sublayers] objectAtIndex:0]];
LƯU Ý Sau khi điều tra thêm, đèn flash đang xảy ra mặc dù không liên tục. Nói chung nó dường như trở nên có thể nhìn thấy khoảng 5-10 giây sau khi nó bắt đầu. Tôi cũng thấy nó xảy ra chạy hai lần liên tiếp ngay cả khi tôi gọi mã một lần.