如何在Objective C项目中使用ALCameraViewController库

时间:2017-12-31 23:19:02

标签: ios objective-c swift camera

文件说要在swift中使用它:

        let cameraViewController = CameraViewController { [weak self] image, asset in
        // Do something with your image here.
        self?.dismiss(animated: true, completion: nil)
    } 
present(cameraViewController, animated: true, completion: nil)

但我不知道如何将其转换为Objective C.。

1 个答案:

答案 0 :(得分:0)

这只是看起来很聪明的代码,因为他在CameraViewController的初始化程序中有Swift默认值。 Objective-C不支持默认值,因此您需要提供它们。来源是right here

这样的事情:

croppingParameters:CroppingParameters = CroppingParameters(),                 allowsLibraryAccess:Bool = true,                 allowsSwapCameraOrientation:Bool = true,                 allowVolumeButtonCapture:Bool = true,                 完成:@escaping CameraViewCompletion

__weak typeof(self) weakSelf = self;
CameraViewController *cameraViewController = [[CameraViewController alloc] 
    initWithCroppingParameters:[CroppingParameters new]
    allowsLibraryAccess: YES
    allowsSwapCameraOrientation: YES
    allowVolumeButtonCapture: YES
    completion: ^(UIImage *image, PHAsset *asset) {
        [weakSelf dismissViewControllerAnimated:YES completion:nil];
    }];

[self presentViewController:cameraViewController animated:YES completion:nil];

但是由于ALCamera项目似乎并不关心Objective-C,所以可能没有完全支持它。