-
Notifications
You must be signed in to change notification settings - Fork 978
How to use (objc)
-
Manually
The system will automatically generate a class of
target-Swfit.h
(target
is your project name), add#import "target-Swift.h"
where you need to use it. -
Others
-
Need add
use_frameworks!
inPodfile
. -
@import ZLPhotoBrowser;
or#import <ZLPhotoBrowser/ZLPhotoBrowser-Swift.h>
.
-
Because the singleton method name
default
inZLPhotoConfiguration
conflicts with theoc
keyword, it cannot be called using dot syntax, and must be called with[ZLPhotoConfiguration default]
.
This class is a configuration class for framework, you can configure each parameter according to your needs.
// example
[ZLPhotoConfiguration default].allowSelectVideo = NO;
This class is used to configure the framework UI style, including colors, languages, images, etc.
// example
[ZLPhotoUIConfiguration default].themeColor = UIColor.blackColor;
ZLPhotoPreviewSheet *ps = [[ZLPhotoPreviewSheet alloc] initWithSelectedAssets:@[]];
//or
ZLPhotoPreviewSheet *ps = [[ZLPhotoPreviewSheet alloc] initWithResults:@[]];
ps.selectImageBlock = ^(NSArray<ZLResultModel *> * _Nonnull results, BOOL isOriginal) {
// your code
};
[ps showPreviewWithAnimate:YES sender:self];
ZLPhotoPreviewSheet *ps = [[ZLPhotoPreviewSheet alloc] initWithSelectedAssets:@[]];
ps.selectImageBlock = ^(NSArray<ZLResultModel *> * _Nonnull results, BOOL isOriginal) {
// your code
};
[ps showPhotoLibraryWithSender:self];
ZLCameraConfiguration *cameraConfig = [ZLPhotoConfiguration default].cameraConfiguration;
// All properties of the camera configuration have default value
cameraConfig.sessionPreset = CaptureSessionPresetHd1920x1080;
cameraConfig.focusMode = FocusModeContinuousAutoFocus;
cameraConfig.exposureMode = ExposureModeContinuousAutoExposure;
cameraConfig.flashMode = FlashModeOff;
cameraConfig.videoExportType = VideoExportTypeMov;
ZLCustomCamera *camera = [[ZLCustomCamera alloc] init];
camera.takeDoneBlock = ^(UIImage * _Nullable image, NSURL * _Nullable videoUrl) {
};
[self showDetailViewController:camera sender:nil];
Because Objective-C array can't contain Enum styles, so this property is invalid in Objective-C.
[ZLPhotoConfiguration default].editImageConfiguration.editImageClipRatios = @[ZLImageClipRatio.custom, ZLImageClipRatio.circle, ZLImageClipRatio.wh1x1, ZLImageClipRatio.wh3x4, ZLImageClipRatio.wh16x9, [[ZLImageClipRatio alloc] initWithTitle:@"1 : 2" whRatio:1.0 / 2.0]];
ZLEditImageViewController *editVC = [[ZLEditImageViewController alloc] initWithImage:image editModel:nil];
editVC.editFinishBlock = ^(UIImage * _Nonnull image, ZLEditImageModel * _Nonnull editModel) {
// your code
};
editVC.modalPresentationStyle = UIModalPresentationFullScreen;
[vc showDetailViewController:editVC sender:nil];
- About image sticker
You must provide a view that implements ZLImageStickerContainerDelegate. See this Demo.
@objc public var imageStickerContainerView: (UIView & ZLImageStickerContainerDelegate)? = nil
@interface CustomFilter : NSObject
+ (UIImage *)filterMethod:(UIImage *)image;
@end
@implementation CustomFilter
+ (UIImage *)filterMethod:(UIImage *)image
{
// 1. create filter.
// 2. process the image.
// 3. return the processed picture.
}
@end
ZLFilter *filter = [[ZLFilter alloc] initWithName:@"custom" applier:^UIImage * _Nonnull(UIImage * _Nonnull image) {
return [CustomFilter filterMethod:image];
}];
[ZLPhotoConfiguration default].editImageConfiguration.filters = @[filter];
// edit local file.
NSURL *fileUrl = [NSURL fileURLWithPath:@"filePath"];
AVAsset *avAsset = [AVAsset assetWithURL:fileUrl];
ZLEditVideoViewController *editVC = [[ZLEditVideoViewController alloc] initWithAvAsset:avAsset animateDismiss:YES];
editVC.editFinishBlock = ^(NSURL * _Nonnull url) {
// your code
};
editVC.modalPresentationStyle = UIModalPresentationFullScreen;
[vc showDetailViewController:editVC sender:nil];
// Need to be consistent with the framework image name.
[ZLPhotoUIConfiguration default].customImageNames = @[@"zl_btn_selected"];
[ZLPhotoUIConfiguration default].customLanguageKeyValue_objc = @[@"previewCamera": @"Camera"];
if (@available(iOS 13.0, *)) {
UIColor *thumbnailBgColor = [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
if (traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
return UIColor.blackColor;
} else {
return UIColor.whiteColor;
}
}];
[ZLPhotoConfiguration default].themeColorDeploy.thumbnailBgColor = thumbnailBgColor;
}
// Must be one of PHAsset, UIImage and URL, framework will filter others.
NSArray *datas = @[...];
NSArray *videoSuffixs = @[@"mp4", @"mov", @"avi", @"rmvb", @"rm", @"flv", @"3gp", @"wmv", @"vob", @"dat", @"m4v", @"f4v", @"mkv"];
ZLImagePreviewController *vc = [[ZLImagePreviewController alloc] initWithDatas:datas index:0 showSelectBtn:YES urlType:^enum ZLURLType(NSURL * _Nonnull url) {
NSString *format = [url.absoluteString componentsSeparatedByString:@"."].lastObject;
if ([videoSuffixs containsObject:format]) {
return ZLURLTypeVideo;
} else {
return ZLURLTypeImage;
}
} urlImageLoader:^(NSURL * _Nonnull url, UIImageView * _Nonnull imageView, void (^ _Nonnull progress)(CGFloat), void (^ _Nonnull loadFinish)(void)) {
[imageView sd_setImageWithURL:url placeholderImage:nil options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {
CGFloat percentage = (CGFloat)receivedSize / (CGFloat)expectedSize;
progress(percentage);
} completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
loadFinish();
}];
}];
vc.doneBlock = ^(NSArray * _Nonnull datas) {
// your code
};
vc.modalPresentationStyle = UIModalPresentationFullScreen;
[self showDetailViewController:vc sender:nil];