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

问题描述 投票:0回答:1

文件说要在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.

ios objective-c swift camera
1个回答
0
投票

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

像这样的东西:

croppingParameters:CroppingParameters = CroppingParameters(),allowsLibraryAccess:Bool = true,allowsSwapCameraOrientation:bool = true,allowVolumeButtonCapture:Bool = true,completion:@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,因此可能没有完全支持它。

© www.soinside.com 2019 - 2024. All rights reserved.