Commit 76ce9b51 authored by huanglu's avatar huanglu

update

parent b888b913
//
// LFBaseEditingController.h
// LFMediaEditingController
//
// Created by LamTsanFeng on 2017/6/9.
// Copyright © 2017年 LamTsanFeng. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface LFBaseEditingController : UIViewController
/** 是否隐藏状态栏 默认YES */
@property (nonatomic, assign) BOOL isHiddenStatusBar;
/// 自定义外观颜色
@property (nonatomic, strong) UIColor *oKButtonTitleColorNormal;
@property (nonatomic, strong) UIColor *cancelButtonTitleColorNormal;
/// 自定义文字
@property (nonatomic, copy) NSString *oKButtonTitle __deprecated_msg("Property deprecated. Use `LFMediaEditingController.strings`");
@property (nonatomic, copy) NSString *cancelButtonTitle __deprecated_msg("Property deprecated. Use `LFMediaEditingController.strings`");
@property (nonatomic, copy) NSString *processHintStr __deprecated_msg("Property deprecated. Use `LFMediaEditingController.strings`");
//- (void)showProgressHUDText:(NSString *)text;
- (void)showProgressHUD;
- (void)hideProgressHUD;
- (void)showProgressVideoHUD;
- (void)setProgress:(float)progress;
/** 初始化 */
- (instancetype)initWithOrientation:(UIInterfaceOrientation)orientation;
@end
//
// LFBaseEditingController.m
// LFMediaEditingController
//
// Created by LamTsanFeng on 2017/6/9.
// Copyright © 2017年 LamTsanFeng. All rights reserved.
//
#import "LFBaseEditingController.h"
#import "LFMediaEditingHeader.h"
#import "UIDevice+LFMEOrientation.h"
@interface LFBaseEditingController ()
{
UIButton *_progressHUD;
UIView *_HUDContainer;
UIActivityIndicatorView *_HUDIndicatorView;
UILabel *_HUDLabel;
UIProgressView *_ProgressView;
}
/** 默认编辑屏幕方向 */
@property (nonatomic, assign) UIInterfaceOrientation orientation;
@end
@implementation LFBaseEditingController
- (instancetype)init
{
return [self initWithOrientation:UIInterfaceOrientationPortrait];
}
- (instancetype)initWithOrientation:(UIInterfaceOrientation)orientation
{
self = [super init];
if (self) {
_orientation = orientation;
/** 因数据可以多次重复编辑,暂时未能处理横竖屏切换的问题。 */
[UIDevice LFME_setOrientation:orientation];
_oKButtonTitleColorNormal = [UIColor colorWithRed:(26/255.0) green:(173/255.0) blue:(25/255.0) alpha:1.0];
_cancelButtonTitleColorNormal = [UIColor colorWithWhite:0.8f alpha:1.f];
_isHiddenStatusBar = YES;
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
NSAssert(self.navigationController, @"You must wrap it with UINavigationController");
self.view.backgroundColor = [UIColor blackColor];
}
- (void)dealloc
{
[self hideProgressHUD];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - 状态栏
- (UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleDefault;
}
- (BOOL)prefersStatusBarHidden
{
return self.isHiddenStatusBar;
}
- (BOOL)shouldAutorotate
{
/** 必须要为YES,开启接受屏幕方向转换,否则会受到其他能横屏的界面影响,无法更正回来 */
return YES;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
UIInterfaceOrientationMask mask = UIInterfaceOrientationMaskPortrait;
switch (self.orientation) {
case UIInterfaceOrientationLandscapeLeft:
mask = UIInterfaceOrientationMaskLandscape;
break;
case UIInterfaceOrientationLandscapeRight:
mask = UIInterfaceOrientationMaskLandscape;
break;
default:
break;
}
return mask;
}
#pragma mark - private
- (void)showProgressHUDText:(NSString *)text isTop:(BOOL)isTop needProcess:(BOOL)needProcess
{
[self hideProgressHUD];
if (!_progressHUD) {
_progressHUD = [UIButton buttonWithType:UIButtonTypeCustom];
[_progressHUD setBackgroundColor:[UIColor clearColor]];
_progressHUD.frame = [UIScreen mainScreen].bounds;
_HUDContainer = [[UIView alloc] init];
_HUDContainer.frame = CGRectMake(([[UIScreen mainScreen] bounds].size.width - 120) / 2, ([[UIScreen mainScreen] bounds].size.height - 90) / 2, 120, 90);
_HUDContainer.layer.cornerRadius = 8;
_HUDContainer.clipsToBounds = YES;
_HUDContainer.backgroundColor = [UIColor darkGrayColor];
_HUDContainer.alpha = 0.7;
_HUDIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
_HUDIndicatorView.frame = CGRectMake(45, 15, 30, 30);
_HUDLabel = [[UILabel alloc] init];
_HUDLabel.frame = CGRectMake(0,40, 120, 50);
_HUDLabel.textAlignment = NSTextAlignmentCenter;
_HUDLabel.font = [UIFont systemFontOfSize:15];
_HUDLabel.textColor = [UIColor whiteColor];
[_HUDContainer addSubview:_HUDLabel];
[_HUDContainer addSubview:_HUDIndicatorView];
[_progressHUD addSubview:_HUDContainer];
}
if (needProcess) {
_HUDContainer.frame = CGRectMake(([[UIScreen mainScreen] bounds].size.width - 120) / 2, ([[UIScreen mainScreen] bounds].size.height - 90) / 2, 120.f, 100.f);
if (!_ProgressView) {
_ProgressView = [[UIProgressView alloc] initWithFrame:CGRectMake(10.f, CGRectGetMaxY(_HUDLabel.frame), CGRectGetWidth(_HUDContainer.frame)-20.f, 2.5f)];
[_HUDContainer addSubview:_ProgressView];
}
}
_HUDLabel.text = text ? text : [NSBundle LFME_localizedStringForKey:@"_LFME_processHintStr"];
[_HUDIndicatorView startAnimating];
UIView *view = isTop ? [[UIApplication sharedApplication] keyWindow] : self.view;
[view addSubview:_progressHUD];
}
- (void)showProgressHUDText:(NSString *)text
{
[self showProgressHUDText:text isTop:NO needProcess:NO];
}
- (void)showProgressHUD
{
[self showProgressHUDText:nil isTop:NO needProcess:NO];
}
- (void)hideProgressHUD {
if (_progressHUD) {
[_HUDIndicatorView stopAnimating];
[_progressHUD removeFromSuperview];
[_ProgressView setProgress:0.f];
}
}
- (void)showProgressVideoHUD
{
[self showProgressHUDText:nil isTop:NO needProcess:YES];
}
- (void)setProgress:(float)progress
{
[_ProgressView setProgress:progress animated:YES];
}
/**
从状态栏下拉或底部栏上滑,跟系统的下拉通知中心手势和上滑控制中心手势冲突。
设置后下拉状态栏只会展示指示器,继续下拉才能将通知中心拉出来。如果返回UIRectEdgeNone则会直接下拉出来。
*/
- (UIRectEdge)preferredScreenEdgesDeferringSystemGestures
{
return UIRectEdgeAll;
}
@end
//
// LFStickerItem+View.h
// LFMediaEditingController
//
// Created by TsanFeng Lam on 2019/6/20.
// Copyright © 2019 lincf0912. All rights reserved.
//
#import "LFStickerItem.h"
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface LFStickerItem (View)
- (UIView *)displayView;
@end
NS_ASSUME_NONNULL_END
//
// LFStickerItem+View.m
// LFMediaEditingController
//
// Created by TsanFeng Lam on 2019/6/20.
// Copyright © 2019 lincf0912. All rights reserved.
//
#import "LFStickerItem+View.h"
#import "LFMEGifView.h"
#import "LFMEVideoView.h"
@implementation LFStickerItem (View)
- (UIView *)displayView
{
if (self.image) {
LFMEGifView *view = [[LFMEGifView alloc] initWithFrame:(CGRect){CGPointZero, self.displayImage.size}];
view.gifImage = self.displayImage;
return view;
} else if (self.asset) {
CGSize videoSize = CGSizeZero;
NSArray *assetVideoTracks = [self.asset tracksWithMediaType:AVMediaTypeVideo];
if (assetVideoTracks.count > 0)
{
// Insert the tracks in the composition's tracks
AVAssetTrack *track = [assetVideoTracks firstObject];
CGSize dimensions = CGSizeApplyAffineTransform(track.naturalSize, track.preferredTransform);
videoSize = CGSizeMake(fabs(dimensions.width), fabs(dimensions.height));
} else {
NSLog(@"Error reading the transformed video track");
}
if (!CGSizeEqualToSize(CGSizeZero, videoSize)) {
CGSize size = CGSizeZero;
size.width = [UIScreen mainScreen].bounds.size.width;
size.height = size.width*videoSize.height/videoSize.width;
videoSize = size;
}
LFMEVideoView *view = [[LFMEVideoView alloc] initWithFrame:(CGRect){CGPointZero, videoSize}];
view.asset = self.asset;
return view;
} else if (self.text) {
UIView *view = [[UIView alloc] initWithFrame:(CGRect){CGPointZero, self.displayImage.size}];
view.layer.contents = (__bridge id _Nullable)(self.displayImage.CGImage);
// view.layer.shadowOpacity = .8;
// view.layer.shadowRadius = 3.0;
// view.layer.shadowColor = ([self.textColor isEqual:[UIColor blackColor]]) ? [UIColor whiteColor].CGColor : [UIColor blackColor].CGColor;
// view.layer.shadowOffset = CGSizeMake(1, 1);
// UIBezierPath *path = [UIBezierPath bezierPathWithRect:view.bounds];
// view.layer.shadowPath = path.CGPath;
return view;
}
NSLog(@"%@ has no displayview available", self);
return nil;
}
@end
//
// LFStickerItem.h
// LFMediaEditingController
//
// Created by TsanFeng Lam on 2019/6/20.
// Copyright © 2019 lincf0912. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "LFText.h"
#import <AVFoundation/AVFoundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface LFStickerItem : NSObject
@property (nonatomic, assign, readonly, getter=isMain) BOOL main;
/** image/gif */
@property (nonatomic, strong) UIImage *image;
/** text */
@property (nonatomic, strong) LFText *text;
/** video */
@property (nonatomic, strong) AVAsset *asset;
/** display(image/text) */
- (UIImage *)displayImage;
- (UIImage *)displayImageAtTime:(NSTimeInterval)time;
/** main view */
+ (instancetype)mainWithImage:(UIImage *)image;
+ (instancetype)mainWithVideo:(AVAsset *)asset;
@end
NS_ASSUME_NONNULL_END
//
// LFStickerItem.m
// LFMediaEditingController
//
// Created by TsanFeng Lam on 2019/6/20.
// Copyright © 2019 lincf0912. All rights reserved.
//
#import "LFStickerItem.h"
#import "NSString+LFMECoreText.h"
#import "NSAttributedString+LFMECoreText.h"
@interface LFStickerItem ()
@property (nonatomic, assign) UIEdgeInsets textInsets; // 控制字体与控件边界的间隙
@property (nonatomic, strong) UIImage *textCacheDisplayImage;
@property (nonatomic, strong) AVAssetImageGenerator *generator;
@end
@implementation LFStickerItem
+ (instancetype)mainWithImage:(UIImage *)image
{
LFStickerItem *item = [[self alloc] initMain];
item.image = image;
return item;
}
+ (instancetype)mainWithVideo:(AVAsset *)asset
{
LFStickerItem *item = [[self alloc] initMain];
item.asset = asset;
return item;
}
- (instancetype)initMain
{
self = [self init];
if (self) {
_main = YES;
}
return self;
}
- (instancetype)init
{
self = [super init];
if (self) {
_textInsets = UIEdgeInsetsMake(5.f, 5.f, 5.f, 5.f);
}
return self;
}
- (void)setText:(LFText *)text
{
_text = text;
_textCacheDisplayImage = nil;
}
- (void)setAsset:(AVAsset *)asset
{
_asset = asset;
_generator = nil;
}
- (UIImage *)displayImage
{
if (self.image) {
return self.image;
} else if (/*self.text.text.length || */self.text.attributedText.length) {
if (_textCacheDisplayImage == nil) {
BOOL useAttrib = self.text.attributedText.length > 0;
CGSize textSize = CGSizeZero;
UIColor *textColor = nil;
if (useAttrib) {
textSize = [self.text.attributedText LFME_sizeWithConstrainedToSize:CGSizeMake([UIScreen mainScreen].bounds.size.width-(self.textInsets.left+self.textInsets.right), CGFLOAT_MAX)];
NSRange range = NSMakeRange(0, 1);
NSDictionary *typingAttributes = [self.text.attributedText attributesAtIndex:0 effectiveRange:&range];
textColor = [typingAttributes objectForKey:NSForegroundColorAttributeName];
} else {
// textSize = [self.text.text LFME_sizeWithConstrainedToWidth:[UIScreen mainScreen].bounds.size.width-(self.textInsets.left+self.textInsets.right) fromFont:self.text.font lineSpace:1.f lineBreakMode:kCTLineBreakByCharWrapping];
// textColor = self.text.textColor;
}
textSize.width += (self.textInsets.left+self.textInsets.right);
textSize.height += (self.textInsets.top+self.textInsets.bottom);
@autoreleasepool {
/** 创建画布 */
UIGraphicsBeginImageContextWithOptions(textSize, NO, 0.0);
CGContextRef context = UIGraphicsGetCurrentContext();
UIColor *shadowColor = ([textColor isEqual:[UIColor blackColor]]) ? [UIColor whiteColor] : [UIColor blackColor];
CGColorRef shadow = [shadowColor colorWithAlphaComponent:0.8f].CGColor;
CGContextSetShadowWithColor(context, CGSizeMake(1, 1), 3.f, shadow);
CGContextSetAllowsAntialiasing(context, YES);
if (useAttrib) {
[self.text.attributedText LFME_drawInContext:context withPosition:CGPointMake(self.textInsets.left, self.textInsets.top) andHeight:textSize.height andWidth:textSize.width];
} else {
// [self.text.text LFME_drawInContext:context withPosition:CGPointMake(self.textInsets.left, self.textInsets.top) andFont:self.text.font andTextColor:self.text.textColor andHeight:textSize.height andWidth:textSize.width linespace:1.f lineBreakMode:kCTLineBreakByCharWrapping];
}
UIImage *temp = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
_textCacheDisplayImage = temp;
}
}
return _textCacheDisplayImage;
}
return nil;
}
- (UIImage *)displayImageAtTime:(NSTimeInterval)time
{
if (self.displayImage.images.count) {
NSInteger frameCount = self.displayImage.images.count;
NSTimeInterval duration = self.displayImage.duration / frameCount;
NSInteger index = time / duration;
index = index % frameCount;
return [self.displayImage.images objectAtIndex:index];
} else if (self.asset) {
if (_generator == nil) {
AVAssetImageGenerator *generator = [AVAssetImageGenerator assetImageGeneratorWithAsset:self.asset];
generator.appliesPreferredTrackTransform = YES;
CMTime tol = CMTimeMakeWithSeconds([@(0.01) floatValue], self.asset.duration.timescale);
generator.requestedTimeToleranceBefore = tol;
generator.requestedTimeToleranceAfter = tol;
_generator = generator;
}
CMTime index = CMTimeMakeWithSeconds(time, self.asset.duration.timescale);
NSError *error;
CGImageRef imageRef = [_generator copyCGImageAtTime:index actualTime:nil error:&error];
UIImage *image = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
return image;
}
return self.displayImage;
}
@end
//
// LFText.h
// LFImagePickerController
//
// Created by LamTsanFeng on 2017/4/5.
// Copyright © 2017年 LamTsanFeng. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface LFText : NSObject
//@property (nonatomic, copy) NSString *text;
//@property (nonatomic, strong) UIFont *font;
//@property (nonatomic, strong) UIColor *textColor;
@property (nonatomic, strong) NSAttributedString *attributedText;
@end
//
// LFText.m
// LFImagePickerController
//
// Created by LamTsanFeng on 2017/4/5.
// Copyright © 2017年 LamTsanFeng. All rights reserved.
//
#import "LFText.h"
@implementation LFText
@end
//
// LFGridLayer.h
// LFImagePickerController
//
// Created by LamTsanFeng on 2017/3/6.
// Copyright © 2017年 LamTsanFeng. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface LFGridLayer : CAShapeLayer
/** 圆形 */
@property (nonatomic, assign, getter=isCircle) BOOL circle;
@property (nonatomic, assign) CGRect gridRect;
- (void)setGridRect:(CGRect)gridRect animated:(BOOL)animated;
- (void)setGridRect:(CGRect)gridRect animated:(BOOL)animated completion:(void (^)(BOOL finished))completion;
//@property (nonatomic, assign) CGFloat lineWidth;
@property (nonatomic, strong) UIColor *bgColor;
@property (nonatomic, strong) UIColor *gridColor;
@end
//
// LFGridLayer.m
// LFImagePickerController
//
// Created by LamTsanFeng on 2017/3/6.
// Copyright © 2017年 LamTsanFeng. All rights reserved.
//
#import "LFGridLayer.h"
NSString *const lfgridLayerAnimtionKey = @"lf_gridLayer_contentsRectAnimate";
@interface LFGridLayer () <CAAnimationDelegate>
@property (nonatomic, copy) void (^callback)(BOOL finished);
@end
@implementation LFGridLayer
- (instancetype)init
{
self = [super init];
if (self) {
// _lineWidth = 1.f;
self.contentsScale = [[UIScreen mainScreen] scale];
_bgColor = [UIColor clearColor];
_gridColor = [UIColor blackColor];
self.shadowColor = [UIColor blackColor].CGColor;
self.shadowRadius = 3.f;
self.shadowOffset = CGSizeZero;
self.shadowOpacity = .5f;
}
return self;
}
- (void)setGridRect:(CGRect)gridRect
{
[self setGridRect:gridRect animated:NO];
}
- (void)setGridRect:(CGRect)gridRect animated:(BOOL)animated
{
[self setGridRect:gridRect animated:animated completion:nil];
}
- (void)setGridRect:(CGRect)gridRect animated:(BOOL)animated completion:(void (^)(BOOL finished))completion
{
_gridRect = gridRect;
if (completion) {
self.callback = completion;
}
CGPathRef path = [self drawGrid];
if (animated) {
CABasicAnimation *animate = [CABasicAnimation animationWithKeyPath:@"path"];
animate.duration = 0.25f;
animate.fromValue = (__bridge id _Nullable)(self.path);
animate.toValue = (__bridge id _Nullable)(path);
// animate.fillMode=kCAFillModeForwards;
animate.removedOnCompletion = NO;
animate.delegate = self;
self.path = path;
[self addAnimation:animate forKey:lfgridLayerAnimtionKey];
} else {
self.path = path;
if (self.callback) {
self.callback(YES);
self.callback = nil;
}
}
}
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
if ([self animationForKey:lfgridLayerAnimtionKey] == anim) {
if (self.callback) {
self.callback(flag);
self.callback = nil;
}
[self removeAnimationForKey:lfgridLayerAnimtionKey];
}
}
- (CGPathRef)drawGrid
{
self.fillColor = self.bgColor.CGColor;
self.strokeColor = self.gridColor.CGColor;
CGRect rct = self.gridRect;
UIBezierPath *path = [[UIBezierPath alloc] init];
if (self.isCircle)
{
[path addArcWithCenter:CGPointMake(CGRectGetMidX(rct), CGRectGetMidY(rct)) radius:rct.size.width/2 startAngle:0 endAngle:2*M_PI clockwise:YES];
} else {
CGFloat dW = 0;
for(int i=0;i<4;++i){ /** 竖线 */
[path moveToPoint:CGPointMake(rct.origin.x+dW, rct.origin.y)];
[path addLineToPoint:CGPointMake(rct.origin.x+dW, rct.origin.y+rct.size.height)];
dW += _gridRect.size.width/3;
}
dW = 0;
for(int i=0;i<4;++i){ /** 横线 */
[path moveToPoint:CGPointMake(rct.origin.x, rct.origin.y+dW)];
[path addLineToPoint:CGPointMake(rct.origin.x+rct.size.width, rct.origin.y+dW)];
dW += rct.size.height/3;
}
/** 偏移量 */
CGFloat offset = 1;
/** 长度 */
CGFloat cornerlength = 15.f;
CGRect newRct = CGRectInset(rct, -offset, -offset);
/** 左上角 */
[path moveToPoint:CGPointMake(CGRectGetMinX(newRct) , CGRectGetMinY(newRct)+cornerlength)];
[path addLineToPoint:CGPointMake(CGRectGetMinX(newRct) , CGRectGetMinY(newRct))];
[path addLineToPoint:CGPointMake(CGRectGetMinX(newRct)+cornerlength , CGRectGetMinY(newRct))];
/** 右上角 */
[path moveToPoint:CGPointMake(CGRectGetMaxX(newRct)-cornerlength , CGRectGetMinY(newRct))];
[path addLineToPoint:CGPointMake(CGRectGetMaxX(newRct) , CGRectGetMinY(newRct))];
[path addLineToPoint:CGPointMake(CGRectGetMaxX(newRct) , CGRectGetMinY(newRct)+cornerlength)];
/** 右下角 */
[path moveToPoint:CGPointMake(CGRectGetMaxX(newRct) , CGRectGetMaxY(newRct)-cornerlength)];
[path addLineToPoint:CGPointMake(CGRectGetMaxX(newRct) , CGRectGetMaxY(newRct))];
[path addLineToPoint:CGPointMake(CGRectGetMaxX(newRct)-cornerlength , CGRectGetMaxY(newRct))];
/** 左下角 */
[path moveToPoint:CGPointMake(CGRectGetMinX(newRct)+cornerlength , CGRectGetMaxY(newRct))];
[path addLineToPoint:CGPointMake(CGRectGetMinX(newRct) , CGRectGetMaxY(newRct))];
[path addLineToPoint:CGPointMake(CGRectGetMinX(newRct) , CGRectGetMaxY(newRct)-cornerlength)];
}
return path.CGPath;
}
@end
//
// LFGridMaskLayer.h
// ClippingText
//
// Created by LamTsanFeng on 2017/3/7.
// Copyright © 2017年 LamTsanFeng. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface LFGridMaskLayer : CAShapeLayer
/** 遮罩颜色 */
@property (nonatomic, assign) CGColorRef maskColor;
/** 圆形 */
@property (nonatomic, assign, getter=isCircle) BOOL circle;
/** 遮罩范围 */
@property (nonatomic, assign, setter=setMaskRect:) CGRect maskRect;
- (void)setMaskRect:(CGRect)maskRect animated:(BOOL)animated;
/** 取消遮罩 */
- (void)clearMask;
- (void)clearMaskWithAnimated:(BOOL)animated;
@end
//
// LFGridMaskLayer.m
// ClippingText
//
// Created by LamTsanFeng on 2017/3/7.
// Copyright © 2017年 LamTsanFeng. All rights reserved.
//
#import "LFGridMaskLayer.h"
@implementation LFGridMaskLayer
@synthesize maskColor = _maskColor;
- (instancetype)init
{
self = [super init];
if (self) {
[self customInit];
}
return self;
}
- (void)customInit
{
self.contentsScale = [[UIScreen mainScreen] scale];
}
- (void)setMaskColor:(CGColorRef)maskColor
{
self.fillColor = maskColor;
self.fillRule = kCAFillRuleEvenOdd;
}
- (CGColorRef)maskColor
{
return self.fillColor;
}
- (void)setMaskRect:(CGRect)maskRect
{
[self setMaskRect:maskRect animated:NO];
}
- (void)setMaskRect:(CGRect)maskRect animated:(BOOL)animated
{
_maskRect = maskRect;
CGPathRef path = nil;
if (CGRectEqualToRect(CGRectZero, maskRect)) {
path = [self drawClearGrid];
} else {
path = [self drawGrid];
}
[self removeAnimationForKey:@"lf_maskLayer_opacityAnimate"];
if (animated) {
CABasicAnimation *animate = [CABasicAnimation animationWithKeyPath:@"opacity"];
animate.duration = 0.25f;
animate.fromValue = @(0.0);
animate.toValue = @(1.0);
self.path = path;
[self addAnimation:animate forKey:@"lf_maskLayer_opacityAnimate"];
} else {
self.path = path;
}
}
- (void)clearMask
{
[self clearMaskWithAnimated:NO];
}
- (void)clearMaskWithAnimated:(BOOL)animated
{
[self setMaskRect:CGRectZero animated:animated];
}
- (CGPathRef)drawGrid
{
CGRect maskRect = self.maskRect;
CGMutablePathRef mPath = CGPathCreateMutable();
CGPathAddRect(mPath, NULL, self.bounds);
if (self.isCircle) {
CGPathAddArc(mPath, NULL, CGRectGetMidX(maskRect), CGRectGetMidY(maskRect), maskRect.size.width/2, 0, 2*M_PI, NO);
} else {
CGPathAddRect(mPath, NULL, maskRect);
}
return mPath;
}
- (CGPathRef)drawClearGrid
{
CGMutablePathRef mPath = CGPathCreateMutable();
CGPathAddRect(mPath, NULL, self.bounds);
CGPathAddRect(mPath, NULL, self.bounds);
return mPath;
}
@end
//
// LFGridView+private.h
// LFMediaEditingController
//
// Created by TsanFeng Lam on 2019/7/30.
// Copyright © 2019 LamTsanFeng. All rights reserved.
//
#import "LFGridView.h"
NS_ASSUME_NONNULL_BEGIN
@interface LFGridView (private)
- (void)setAspectRatioWithoutDelegate:(LFGridViewAspectRatioType)aspectRatio;
@end
NS_ASSUME_NONNULL_END
//
// LFGridView.h
// ClippingText
//
// Created by LamTsanFeng on 2017/3/7.
// Copyright © 2017年 LamTsanFeng. All rights reserved.
//
#import <UIKit/UIKit.h>
typedef NS_ENUM(NSUInteger, LFGridViewAspectRatioType) {
LFGridViewAspectRatioType_None,
LFGridViewAspectRatioType_Original,
LFGridViewAspectRatioType_1x1,
LFGridViewAspectRatioType_3x2,
LFGridViewAspectRatioType_4x3,
LFGridViewAspectRatioType_5x3,
LFGridViewAspectRatioType_15x9,
LFGridViewAspectRatioType_16x9,
LFGridViewAspectRatioType_16x10,
};
@protocol LFGridViewDelegate;
@interface LFGridView : UIView
@property (nonatomic, assign) CGRect gridRect;
- (void)setGridRect:(CGRect)gridRect animated:(BOOL)animated;
- (void)setGridRect:(CGRect)gridRect maskLayer:(BOOL)isMaskLayer animated:(BOOL)animated;
- (void)setGridRect:(CGRect)gridRect maskLayer:(BOOL)isMaskLayer animated:(BOOL)animated completion:(void (^)(BOOL finished))completion;
/** 最小尺寸 CGSizeMake(80, 80); */
@property (nonatomic, assign) CGSize controlMinSize;
/** 最大尺寸 CGRectInset(self.bounds, 20, 20) */
@property (nonatomic, assign) CGRect controlMaxRect;
/** 原图尺寸 */
@property (nonatomic, assign) CGSize controlSize;
/** 显示遮罩层(触发拖动条件必须设置为YES)default is YES */
@property (nonatomic, assign) BOOL showMaskLayer;
/** 是否正在拖动 */
@property(nonatomic,readonly,getter=isDragging) BOOL dragging;
/** 比例是否水平翻转 */
@property (nonatomic, assign) BOOL aspectRatioHorizontally;
/** 设置固定比例 */
@property (nonatomic, assign) LFGridViewAspectRatioType aspectRatio;
- (void)setAspectRatio:(LFGridViewAspectRatioType)aspectRatio animated:(BOOL)animated;
@property (nonatomic, weak) id<LFGridViewDelegate> delegate;
/** 长宽比例描述 */
- (NSArray <NSString *>*)aspectRatioDescs;
@end
@protocol LFGridViewDelegate <NSObject>
- (void)lf_gridViewDidBeginResizing:(LFGridView *)gridView;
- (void)lf_gridViewDidResizing:(LFGridView *)gridView;
- (void)lf_gridViewDidEndResizing:(LFGridView *)gridView;
/** 调整长宽比例 */
- (void)lf_gridViewDidAspectRatio:(LFGridView *)gridView;
@end
//
// LFResizeControl.h
// ClippingText
//
// Created by LamTsanFeng on 2017/3/7.
// Copyright © 2017年 LamTsanFeng. All rights reserved.
//
#import <UIKit/UIKit.h>
@protocol lf_resizeConrolDelegate;
@interface LFResizeControl : UIView
@property (weak, nonatomic) id<lf_resizeConrolDelegate> delegate;
@property (nonatomic, readonly) CGPoint translation;
@property (nonatomic, getter=isEnabled) BOOL enabled;
@end
@protocol lf_resizeConrolDelegate <NSObject>
- (void)lf_resizeConrolDidBeginResizing:(LFResizeControl *)resizeConrol;
- (void)lf_resizeConrolDidResizing:(LFResizeControl *)resizeConrol;
- (void)lf_resizeConrolDidEndResizing:(LFResizeControl *)resizeConrol;
@end
//
// LFResizeControl.m
// ClippingText
//
// Created by LamTsanFeng on 2017/3/7.
// Copyright © 2017年 LamTsanFeng. All rights reserved.
//
#import "LFResizeControl.h"
@interface LFResizeControl ()
@property (nonatomic, readwrite) CGPoint translation;
@property (nonatomic) CGPoint startPoint;
@property (nonatomic, strong) UIPanGestureRecognizer *gestureRecognizer;
@end
@implementation LFResizeControl
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor clearColor];
UIPanGestureRecognizer *gestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
[self addGestureRecognizer:gestureRecognizer];
_gestureRecognizer = gestureRecognizer;
}
return self;
}
- (BOOL)isEnabled
{
return _gestureRecognizer.isEnabled;
}
- (void)setEnabled:(BOOL)enabled
{
_gestureRecognizer.enabled = enabled;
}
- (void)handlePan:(UIPanGestureRecognizer *)gestureRecognizer
{
if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
CGPoint translationInView = [gestureRecognizer translationInView:self.superview];
self.startPoint = CGPointMake(roundf(translationInView.x), translationInView.y);
if ([self.delegate respondsToSelector:@selector(lf_resizeConrolDidBeginResizing:)]) {
[self.delegate lf_resizeConrolDidBeginResizing:self];
}
} else if (gestureRecognizer.state == UIGestureRecognizerStateChanged) {
CGPoint translation = [gestureRecognizer translationInView:self.superview];
self.translation = CGPointMake(roundf(self.startPoint.x + translation.x),
roundf(self.startPoint.y + translation.y));
if ([self.delegate respondsToSelector:@selector(lf_resizeConrolDidResizing:)]) {
[self.delegate lf_resizeConrolDidResizing:self];
}
} else if (gestureRecognizer.state == UIGestureRecognizerStateEnded || gestureRecognizer.state == UIGestureRecognizerStateCancelled) {
if ([self.delegate respondsToSelector:@selector(lf_resizeConrolDidEndResizing:)]) {
[self.delegate lf_resizeConrolDidEndResizing:self];
}
}
}
@end
//
// LFMaskLayer.h
// DrawTest
//
// Created by LamTsanFeng on 2017/3/3.
// Copyright © 2017年 LamTsanFeng. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface LFBlurBezierPath : UIBezierPath
@property (nonatomic, assign) BOOL isClear;
@end
@interface LFMaskLayer : CALayer
@property (nonatomic, strong) NSMutableArray <LFBlurBezierPath *>*lineArray;
@end
//
// LFMaskLayer.m
// DrawTest
//
// Created by LamTsanFeng on 2017/3/3.
// Copyright © 2017年 LamTsanFeng. All rights reserved.
//
#import "LFMaskLayer.h"
@implementation LFBlurBezierPath
@end
@implementation LFMaskLayer
- (instancetype)init
{
self = [super init];
if (self) {
self.contentsScale = [[UIScreen mainScreen] scale];
_lineArray = [@[] mutableCopy];
}
return self;
}
- (void)drawInContext:(CGContextRef)context
{
UIGraphicsPushContext( context );
CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetLineJoin(context, kCGLineJoinRound);
for (LFBlurBezierPath *path in self.lineArray) {
if (path.isClear) {
CGContextSetBlendMode( context, kCGBlendModeClear );
} else {
CGContextSetBlendMode( context, kCGBlendModeNormal );
}
// [[UIColor darkGrayColor] setStroke];
[path stroke];
}
UIGraphicsPopContext();
}
@end
//
// LFSplashLayer.h
// LFMediaEditingController
//
// Created by LamTsanFeng on 2017/6/7.
// Copyright © 2017年 LamTsanFeng. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface LFSplashBlur : NSObject
//@property (nonatomic, assign) CGPoint point;
@property (nonatomic, assign) CGRect rect;
@property (nonatomic, strong) UIColor *color;
@end
@interface LFSplashImageBlur : LFSplashBlur
@property (nonatomic, copy) NSString *imageName;
@end
@interface LFSplashLayer : CALayer
@property (nonatomic, strong) NSMutableArray <LFSplashBlur *>*lineArray;
@end
//
// LFSplashLayer.m
// LFMediaEditingController
//
// Created by LamTsanFeng on 2017/6/7.
// Copyright © 2017年 LamTsanFeng. All rights reserved.
//
#import "LFSplashLayer.h"
#import "LFMediaEditingHeader.h"
#define radiansToDegrees(x) (180.0 * x / M_PI)
CGFloat angleBetweenPoints(CGPoint startPoint, CGPoint endPoint) {
CGPoint Xpoint = CGPointMake(startPoint.x + 100, startPoint.y);
CGFloat a = endPoint.x - startPoint.x;
CGFloat b = endPoint.y - startPoint.y;
CGFloat c = Xpoint.x - startPoint.x;
CGFloat d = Xpoint.y - startPoint.y;
CGFloat rads = acos(((a*c) + (b*d)) / ((sqrt(a*a + b*b)) * (sqrt(c*c + d*d))));
if (startPoint.y>endPoint.y) {
rads = -rads;
}
return rads;
}
CGFloat angleBetweenLines(CGPoint line1Start, CGPoint line1End, CGPoint line2Start, CGPoint line2End) {
CGFloat a = line1End.x - line1Start.x;
CGFloat b = line1End.y - line1Start.y;
CGFloat c = line2End.x - line2Start.x;
CGFloat d = line2End.y - line2Start.y;
CGFloat rads = acos(((a*c) + (b*d)) / ((sqrt(a*a + b*b)) * (sqrt(c*c + d*d))));
return radiansToDegrees(rads);
}
@implementation LFSplashBlur
@end
@implementation LFSplashImageBlur
@end
@implementation LFSplashLayer
- (instancetype)init
{
self = [super init];
if (self) {
self.contentsScale = [[UIScreen mainScreen] scale];
self.backgroundColor = [UIColor clearColor].CGColor;
_lineArray = [@[] mutableCopy];
}
return self;
}
- (void)drawInContext:(CGContextRef)context
{
@autoreleasepool {
UIGraphicsPushContext( context );
[[UIColor clearColor] setFill];
UIRectFill(self.bounds);
CGContextSetLineCap(context, kCGLineCapSquare);
CGContextSetLineJoin(context, kCGLineJoinMiter);
for (NSInteger i=0; i<self.lineArray.count; i++) {
LFSplashBlur *blur = self.lineArray[i];
CGRect rect = blur.rect;
if ([blur isMemberOfClass:[LFSplashImageBlur class]]) {
UIImage *image = bundleEditImageNamed(((LFSplashImageBlur *)blur).imageName);
if (image) {
/** 创建颜色图片 */
CGColorSpaceRef colorRef = CGColorSpaceCreateDeviceRGB();
CGContextRef contextRef = CGBitmapContextCreate(nil, image.size.width, image.size.height, 8, image.size.width*4, colorRef, kCGImageAlphaPremultipliedFirst);
CGRect imageRect = CGRectMake(0, 0, image.size.width, image.size.height);
CGContextClipToMask(contextRef, imageRect, image.CGImage);
CGContextSetFillColorWithColor(contextRef, (blur.color ? blur.color.CGColor : [UIColor clearColor].CGColor));
CGContextFillRect(contextRef,imageRect);
/** 生成图片 */
CGImageRef imageRef = CGBitmapContextCreateImage(contextRef);
CGContextDrawImage(context, rect, imageRef);
CGImageRelease(imageRef);
CGContextRelease(contextRef);
CGColorSpaceRelease(colorRef);
}
} else {
// 设置描边颜色
// CGContextSetStrokeColorWithColor(context, (blur.color ? blur.color.CGColor : [UIColor clearColor].CGColor));
// 模糊矩形可以用到,用于填充矩形
CGContextSetFillColorWithColor(context, (blur.color ? blur.color.CGColor : [UIColor clearColor].CGColor));
// 模糊矩形 填充 画完一个小正方形
CGContextFillRect(context, rect);
}
}
UIGraphicsPopContext();
}
}
@end
//
// LFMovingView.h
// LFImagePickerController
//
// Created by LamTsanFeng on 2017/2/24.
// Copyright © 2017年 LamTsanFeng. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "LFStickerItem.h"
NS_ASSUME_NONNULL_BEGIN
@interface LFMovingView : UIView
/** active sticker view */
+ (void)setActiveEmoticonView:(LFMovingView * __nullable)view;
/** 初始化 */
- (instancetype)initWithItem:(LFStickerItem *)item;
/** 缩放率 0.2~3.0 */
- (void)setScale:(CGFloat)scale;
- (void)setScale:(CGFloat)scale rotation:(CGFloat)rotation;
/** 最小缩放率 默认0.2 */
@property (nonatomic, assign) CGFloat minScale;
/** 最大缩放率 默认3.0 */
@property (nonatomic, assign) CGFloat maxScale;
/** 显示界面的缩放率,例如在UIScrollView上显示,scrollView放大了5倍,movingView的视图控件会显得较大,这个属性是适配当前屏幕的比例调整控件大小 */
@property (nonatomic, assign) CGFloat screenScale;
/** Delayed deactivated time */
@property (nonatomic, assign) CGFloat deactivatedDelay;
@property (nonatomic, readonly) UIView *view;
@property (nonatomic, strong) LFStickerItem *item;
@property (nonatomic, readonly) CGFloat scale;
@property (nonatomic, readonly) CGFloat rotation;
@property (nonatomic, readonly) BOOL isActive;
@property (nonatomic, copy, nullable) void(^tapEnded)(LFMovingView *view);
@property (nonatomic, copy, nullable) BOOL(^moveCenter)(CGRect rect);
@end
NS_ASSUME_NONNULL_END
//
// BaibanView.h
// TestOC
//
// Created by 李亚军 on 2017/2/8.
// Copyright © 2017年 zyyj. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "YJBezierPath.h"
@interface BaibanView : UIView
@property (nonatomic,strong) YJBezierPath *bezierPath;
//画笔的颜色
@property (nonatomic,copy) UIColor *lineColor;
//是否是橡皮擦
@property (nonatomic,assign) BOOL isErase;
/** 数据 */
@property (nonatomic, strong) NSDictionary *data;
@property (nonatomic, copy) void(^drawBegan)(void);
@property (nonatomic, copy) void(^drawEnded)(void);
@end
//
// LFDrawView.h
// LFImagePickerController
//
// Created by LamTsanFeng on 2017/2/23.
// Copyright © 2017年 LamTsanFeng. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface LFDrawView : UIView
/** 线粗 */
@property (nonatomic, assign) CGFloat lineWidth;
/** 线颜色 */
@property (nonatomic, strong) UIColor *lineColor;
/** 正在绘画 */
@property (nonatomic, readonly) BOOL isDrawing;
@property (nonatomic, copy) void(^drawBegan)(void);
@property (nonatomic, copy) void(^drawEnded)(void);
/** 数据 */
@property (nonatomic, strong) NSDictionary *data;
/** 是否可撤销 */
- (BOOL)canUndo;
//撤销
- (void)undo;
//清空
- (void)clear;
@end
//
// LFDrawView.m
// LFImagePickerController
//
// Created by LamTsanFeng on 2017/2/23.
// Copyright © 2017年 LamTsanFeng. All rights reserved.
//
#import "LFDrawView.h"
inline static CGPoint LFDrawMidPoint(CGPoint p0, CGPoint p1) {
return (CGPoint) {
(p0.x + p1.x) / 2.0,
(p0.y + p1.y) / 2.0
};
}
NSString *const kLFDrawViewData = @"LFDrawViewData";
@interface LFDrawBezierPath : UIBezierPath
@property (nonatomic, strong) UIColor *color;
@property (nonatomic, assign) CGPoint previousPoint;
@property (nonatomic,assign) BOOL isErase;
@end
@implementation LFDrawBezierPath
@end
@interface LFDrawView ()
{
BOOL _isWork;
BOOL _isBegan;
}
/** 笔画 */
@property (nonatomic, strong) NSMutableArray <LFDrawBezierPath *>*lineArray;
/** 图层 */
@property (nonatomic, strong) NSMutableArray <CAShapeLayer *>*slayerArray;
@end
@implementation LFDrawView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self customInit];
}
return self;
}
//- (void)setFrame:(CGRect)frame
//{
// [super setFrame:frame];
// [[self.layer sublayers] enumerateObjectsUsingBlock:^(CALayer * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
// obj.frame = self.bounds;
// }];
//}
- (void)customInit
{
_lineWidth = 5.f;
_lineColor = [UIColor redColor];
_slayerArray = [@[] mutableCopy];
_lineArray = [@[] mutableCopy];
self.backgroundColor = [UIColor clearColor];
self.clipsToBounds = YES;
self.exclusiveTouch = YES;
// self.layer.anchorPoint = CGPointMake(0, 0);
// self.layer.position = CGPointMake(0, 0);
}
#pragma mark - 创建图层
- (CAShapeLayer *)createShapeLayer:(LFDrawBezierPath *)path
{
/** 1、渲染快速。CAShapeLayer使用了硬件加速,绘制同一图形会比用Core Graphics快很多。
2、高效使用内存。一个CAShapeLayer不需要像普通CALayer一样创建一个寄宿图形,所以无论有多大,都不会占用太多的内存。
3、不会被图层边界剪裁掉。
4、不会出现像素化。 */
CAShapeLayer *slayer = [CAShapeLayer layer];
slayer.path = path.CGPath;
slayer.backgroundColor = [UIColor clearColor].CGColor;
slayer.fillColor = [UIColor clearColor].CGColor;
slayer.lineCap = kCALineCapRound;
slayer.lineJoin = kCALineJoinRound;
slayer.strokeColor = path.color.CGColor;
slayer.lineWidth = path.lineWidth;
return slayer;
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
if ([event allTouches].count == 1) {
_isWork = NO;
_isBegan = YES;
//1、每次触摸的时候都应该去创建一条贝塞尔曲线
LFDrawBezierPath *path = [LFDrawBezierPath new];
//2、移动画笔
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self];
//设置线宽
path.lineWidth = 4.0f;
path.lineCapStyle = kCGLineCapRound; //线条拐角
path.lineJoinStyle = kCGLineJoinRound; //终点处理
[path moveToPoint:point];
path.previousPoint = point; // 保存上一个节点
NSLog(@"previousPoint : %@", NSStringFromCGPoint(point));
path.isErase = self.lineColor == [UIColor clearColor];
//设置颜色
path.color = self.lineColor;//保存线条当前颜色
[self.lineArray addObject:path];
CAShapeLayer *slayer = [self createShapeLayer:path];
[self.layer addSublayer:slayer];
[self.slayerArray addObject:slayer];
}
[super touchesBegan:touches withEvent:event];
}
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
if (_isBegan || _isWork) {
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self];
LFDrawBezierPath *path = self.lineArray.lastObject;
if (!CGPointEqualToPoint(path.currentPoint, point)) {
if (_isBegan && self.drawBegan) self.drawBegan();
_isBegan = NO;
_isWork = YES;
CGPoint midPoint = LFDrawMidPoint(path.previousPoint, point);
NSLog(@"midPoint : %@", NSStringFromCGPoint(point));
// 使用二次曲线方程式
[path addQuadCurveToPoint:midPoint controlPoint:path.previousPoint];
path.previousPoint = point;
CAShapeLayer *slayer = self.slayerArray.lastObject;
slayer.path = path.CGPath;
}
}
[super touchesMoved:touches withEvent:event];
// [self setNeedsDisplay];
}
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event{
if (_isWork) {
if (self.drawEnded) self.drawEnded();
} else {
if ((_isBegan)) {
[self undo];
}
}
_isBegan = NO;
_isWork = NO;
[super touchesEnded:touches withEvent:event];
// [self setNeedsDisplay];
}
- (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
if (_isWork) {
if (self.drawEnded) self.drawEnded();
} else {
if ((_isBegan)) {
[self undo];
}
}
_isBegan = NO;
_isWork = NO;
[super touchesCancelled:touches withEvent:event];
[self setNeedsDisplay];
}
-(void)drawRect:(CGRect)rect{
if (self.lineArray.count) {
for (LFDrawBezierPath *path in self.lineArray) {
if (path.isErase) {
[self.backgroundColor setStroke];
}else{
[path.color setStroke];
}
path.lineCapStyle = kCGLineCapRound;
path.lineJoinStyle = kCGLineCapRound;
if (path.isErase) {
path.lineWidth = 10; // 这里可抽取出来枚举定义
[path strokeWithBlendMode:kCGBlendModeDestinationIn alpha:1.0];
}else{
path.lineWidth = 4.0f;
[path strokeWithBlendMode:kCGBlendModeNormal alpha:1.0];
}
[path stroke];
}
}
[super drawRect:rect];
}
//- (void)drawRect:(CGRect)rect{
// //遍历数组,绘制曲线
// for (LFDrawBezierPath *path in self.lineArray) {
// [path.color setStroke];
// [path setLineCapStyle:kCGLineCapRound];
// [path stroke];
// }
//}
- (BOOL)isDrawing
{
return _isWork;
}
/** 是否可撤销 */
- (BOOL)canUndo
{
return self.lineArray.count;
}
//撤销
- (void)undo
{
[self.slayerArray.lastObject removeFromSuperlayer];
[self.slayerArray removeLastObject];
[self.lineArray removeLastObject];
}
//清空
- (void)clear
{
for (CAShapeLayer *layer in self.slayerArray) {
[layer removeFromSuperlayer];
}
[self.slayerArray removeAllObjects];
[self.lineArray removeAllObjects];
}
#pragma mark - 数据
- (NSDictionary *)data
{
if (self.lineArray.count) {
return @{kLFDrawViewData:[self.lineArray copy]};
}
return nil;
}
- (void)setData:(NSDictionary *)data
{
NSArray *lineArray = data[kLFDrawViewData];
if (lineArray.count) {
for (LFDrawBezierPath *path in lineArray) {
CAShapeLayer *slayer = [self createShapeLayer:path];
[self.layer addSublayer:slayer];
[self.slayerArray addObject:slayer];
}
[self.lineArray addObjectsFromArray:lineArray];
}
}
@end
//
// LFFilterView.h
// LFMediaEditingController
//
// Created by TsanFeng Lam on 2018/8/6.
// Copyright © 2018年 LamTsanFeng. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "LFColorMatrixType.h"
@interface LFFilterView : UIView
@property (nonatomic, strong) UIImage *image;
@property (nonatomic, readonly) UIImage *filterImage;
@property (nonatomic, assign) LFColorMatrixType cmType;
/** 数据 */
@property (nonatomic, strong) NSDictionary *data;
@end
//
// LFFilterView.m
// LFMediaEditingController
//
// Created by TsanFeng Lam on 2018/8/6.
// Copyright © 2018年 LamTsanFeng. All rights reserved.
//
#import "LFFilterView.h"
NSString *const kLFFilterViewData = @"LFFilterViewData";
@interface LFFilterView ()
@property (nonatomic, weak) UIImageView *imageView;
@property (nonatomic, strong) UIImage *defaultImage;
@end
@implementation LFFilterView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self customInit];
}
return self;
}
- (void)customInit
{
self.backgroundColor = [UIColor clearColor];
self.contentMode = UIViewContentModeScaleAspectFit;
UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.bounds];
// imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
imageView.backgroundColor = [UIColor clearColor];
imageView.contentMode = UIViewContentModeScaleAspectFit;
[self addSubview:imageView];
self.imageView = imageView;
}
- (void)layoutSubviews
{
[super layoutSubviews];
self.imageView.frame = self.bounds;
}
- (UIImage *)filterImage
{
return self.imageView.image;
}
- (UIImage *)image
{
return self.defaultImage;
}
- (void)setImage:(UIImage *)image
{
self.defaultImage = image;
self.imageView.image = image;
/** 重新生成滤镜 */
self.cmType = self.cmType;
}
- (void)setCmType:(LFColorMatrixType)cmType
{
_cmType = cmType;
self.imageView.image = lf_colorMatrixImage(self.defaultImage, cmType);
}
#pragma mark - 数据
- (NSDictionary *)data
{
if (self.cmType != LFColorMatrixType_None) {
return @{kLFFilterViewData:@(self.cmType)};
}
return nil;
}
- (void)setData:(NSDictionary *)data
{
self.cmType = [data[kLFFilterViewData] integerValue];
}
@end
//
// LFSplashView_new.h
// LFMediaEditingController
//
// Created by LamTsanFeng on 2017/6/7.
// Copyright © 2017年 LamTsanFeng. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "LFMediaEditingType.h"
@interface LFSplashView : UIView
/** 数据 */
@property (nonatomic, strong) NSDictionary *data;
/** 马赛克大小 */
@property (nonatomic, assign) CGFloat squareWidth;
/** 画笔大小 */
@property (nonatomic, assign) CGSize paintSize;
/** 正在绘画 */
@property (nonatomic, readonly) BOOL isDrawing;
@property (nonatomic, copy) void(^splashBegan)(void);
@property (nonatomic, copy) void(^splashEnded)(void);
/** 绘画颜色 */
@property (nonatomic, copy) UIColor *(^splashColor)(CGPoint point);
/** 改变模糊状态 */
@property (nonatomic, assign) LFSplashStateType state;
/** 是否可撤销 */
- (BOOL)canUndo;
//撤销
- (void)undo;
@end
//
// LFSplashView_new.m
// LFMediaEditingController
//
// Created by LamTsanFeng on 2017/6/7.
// Copyright © 2017年 LamTsanFeng. All rights reserved.
//
#import "LFSplashView.h"
#import "LFSplashLayer.h"
#import "LFMediaEditingHeader.h"
NSString *const kLFSplashViewData = @"LFSplashViewData";
NSString *const kLFSplashViewData_layerArray = @"LFSplashViewData_layerArray";
NSString *const kLFSplashViewData_frameArray = @"LFSplashViewData_frameArray";
@interface LFSplashView ()
{
BOOL _isWork;
BOOL _isBegan;
}
/** 图层 */
@property (nonatomic, strong) NSMutableArray <LFSplashLayer *>*layerArray;
/** 已显示坐标 */
@property (nonatomic, strong) NSMutableArray <NSValue *>*frameArray;
@property (nonatomic, assign) BOOL isErase;
@end
@implementation LFSplashView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self customInit];
}
return self;
}
- (void)customInit
{
_squareWidth = 15.f;
_paintSize = CGSizeMake(50, 50);
_state = LFSplashStateType_Mosaic;
_layerArray = [@[] mutableCopy];
_frameArray = [@[] mutableCopy];
}
- (CGPoint)divideMosaicPoint:(CGPoint)point
{
CGFloat scope = self.squareWidth;
int x = point.x/scope;
int y = point.y/scope;
return CGPointMake(x*scope, y*scope);
}
- (NSArray <NSValue *>*)divideMosaicRect:(CGRect)rect
{
CGFloat scope = self.squareWidth;
NSMutableArray *array = @[].mutableCopy;
if (CGRectEqualToRect(CGRectZero, rect)) {
return array;
}
CGFloat minX = CGRectGetMinX(rect);
CGFloat maxX = CGRectGetMaxX(rect);
CGFloat minY = CGRectGetMinY(rect);
CGFloat maxY = CGRectGetMaxY(rect);
/** 左上角 */
CGPoint leftTop = [self divideMosaicPoint:CGPointMake(minX, minY)];
/** 右下角 */
CGPoint rightBoom = [self divideMosaicPoint:CGPointMake(maxX, maxY)];
NSInteger countX = (rightBoom.x - leftTop.x)/scope;
NSInteger countY = (rightBoom.y - leftTop.y)/scope;
for (NSInteger i = 0; i < countX; i++) {
for (NSInteger j = 0; j < countY; j++) {
CGPoint point = CGPointMake(leftTop.x + i * scope, leftTop.y + j * scope);
NSValue *value = [NSValue valueWithCGPoint:point];
[array addObject:value];
}
}
return array;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
if (touches.allObjects.count == 1) {
_isWork = NO;
_isBegan = YES;
//1、触摸坐标
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self];
//2、创建LFSplashBlur
if (self.state == LFSplashStateType_Mosaic) {
CGPoint mosaicPoint = [self divideMosaicPoint:point];
NSValue *value = [NSValue valueWithCGPoint:mosaicPoint];
if (![self.frameArray containsObject:value]) {
[self.frameArray addObject:value];
LFSplashBlur *blur = [LFSplashBlur new];
blur.rect = CGRectMake(mosaicPoint.x, mosaicPoint.y, self.squareWidth, self.squareWidth);
blur.color = self.splashColor ? self.splashColor(blur.rect.origin) : nil;
LFSplashLayer *layer = [LFSplashLayer layer];
layer.frame = self.bounds;
[layer.lineArray addObject:blur];
[self.layer addSublayer:layer];
[self.layerArray addObject:layer];
} else {
LFSplashLayer *layer = [LFSplashLayer layer];
layer.frame = self.bounds;
[self.layer addSublayer:layer];
[self.layerArray addObject:layer];
}
} else if (self.state == LFSplashStateType_Paintbrush) {
LFSplashImageBlur *blur = [LFSplashImageBlur new];
blur.rect = CGRectMake(point.x-self.paintSize.width/2, point.y-self.paintSize.height/2, self.paintSize.width, self.paintSize.height);
blur.imageName = @"EditImageMosaicBrush.png";
blur.color = self.splashColor ? self.splashColor(blur.rect.origin) : nil;
LFSplashLayer *layer = [LFSplashLayer layer];
layer.frame = self.bounds;
[layer.lineArray addObject:blur];
[self.layer addSublayer:layer];
[self.layerArray addObject:layer];
}
}
[super touchesBegan:touches withEvent:event];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
if (_isBegan || _isWork) {
//1、触摸坐标
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self];
/** 获取上一个对象坐标判断是否重叠 */
LFSplashLayer *layer = self.layerArray.lastObject;
LFSplashBlur *prevBlur = layer.lineArray.lastObject;
if (self.state == LFSplashStateType_Mosaic) {
CGPoint mosaicPoint = [self divideMosaicPoint:point];
NSValue *value = [NSValue valueWithCGPoint:mosaicPoint];
if (![self.frameArray containsObject:value]) {
if (_isBegan && self.splashBegan) self.splashBegan();
_isWork = YES;
_isBegan = NO;
[self.frameArray addObject:value];
//2、创建LFSplashBlur
LFSplashBlur *blur = [LFSplashBlur new];
blur.rect = CGRectMake(mosaicPoint.x, mosaicPoint.y, self.squareWidth, self.squareWidth);
blur.color = self.splashColor ? self.splashColor(blur.rect.origin) : nil;
[layer.lineArray addObject:blur];
[layer setNeedsDisplay];
}
} else if (self.state == LFSplashStateType_Paintbrush) {
/** 限制绘画的间隙 */
if (CGRectContainsPoint(prevBlur.rect, point) == NO) {
if (_isBegan && self.splashBegan) self.splashBegan();
_isWork = YES;
_isBegan = NO;
//2、创建LFSplashBlur
LFSplashImageBlur *blur = [LFSplashImageBlur new];
blur.imageName = @"EditImageMosaicBrush.png";
blur.color = self.splashColor ? self.splashColor(point) : nil;
/** 新增随机位置 */
int x = self.paintSize.width + MIN(1, (int)(self.paintSize.width*0.4));
float randomX = floorf(arc4random()%x) - x/2;
blur.rect = CGRectMake(point.x-self.paintSize.width/2 + randomX, point.y-self.paintSize.height/2, self.paintSize.width, self.paintSize.height);
[layer.lineArray addObject:blur];
/** 新增额外对象 密集图片 */
[layer setNeedsDisplay];
/** 扩大范围 */
CGRect paintRect = CGRectInset(blur.rect, -self.squareWidth, -self.squareWidth);
[self.frameArray removeObjectsInArray:[self divideMosaicRect:paintRect]];
}
}
}
[super touchesMoved:touches withEvent:event];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
if (_isWork) {
LFSplashLayer *layer = self.layerArray.lastObject;
if (layer.lineArray.count < 2) {
[self undo];
} else {
if (self.splashEnded) self.splashEnded();
}
} else {
if ((_isBegan)) {
[self undo];
}
}
_isBegan = NO;
_isWork = NO;
[super touchesEnded:touches withEvent:event];
}
- (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
if (_isWork) {
LFSplashLayer *layer = self.layerArray.lastObject;
if (layer.lineArray.count < 2) {
[self undo];
} else {
if (self.splashEnded) self.splashEnded();
}
} else {
if ((_isBegan)) {
[self undo];
}
}
_isBegan = NO;
_isWork = NO;
[super touchesCancelled:touches withEvent:event];
}
- (BOOL)isDrawing
{
return _isWork;
}
/** 是否可撤销 */
- (BOOL)canUndo
{
return self.layerArray.count;
}
//撤销
- (void)undo
{
LFSplashLayer *layer = self.layerArray.lastObject;
if ([layer.lineArray.firstObject isMemberOfClass:[LFSplashBlur class]]) {
for (LFSplashBlur *blur in layer.lineArray) {
[self.frameArray removeObject:[NSValue valueWithCGPoint:blur.rect.origin]];
}
}
[layer removeFromSuperlayer];
[self.layerArray removeLastObject];
}
#pragma mark - 数据
- (NSDictionary *)data
{
if (self.layerArray.count) {
NSMutableArray *lineArray = [@[] mutableCopy];
for (LFSplashLayer *layer in self.layerArray) {
[lineArray addObject:layer.lineArray];
}
return @{kLFSplashViewData:@{
kLFSplashViewData_layerArray:[lineArray copy],
kLFSplashViewData_frameArray:[self.frameArray copy]
}};
}
return nil;
}
- (void)setData:(NSDictionary *)data
{
NSDictionary *dataDict = data[kLFSplashViewData];
NSArray *lineArray = dataDict[kLFSplashViewData_layerArray];
for (NSArray *subLineArray in lineArray) {
LFSplashLayer *layer = [LFSplashLayer layer];
layer.frame = self.bounds;
[layer.lineArray addObjectsFromArray:subLineArray];
[self.layer addSublayer:layer];
[self.layerArray addObject:layer];
[layer setNeedsDisplay];
}
NSArray *frameArray = dataDict[kLFSplashViewData_frameArray];
[self.frameArray addObjectsFromArray:frameArray];
}
@end
//
// LFStickerView.h
// LFImagePickerController
//
// Created by LamTsanFeng on 2017/2/24.
// Copyright © 2017年 LamTsanFeng. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "LFStickerItem.h"
@class LFText;
@interface LFStickerView : UIView
/** 取消当前激活的贴图 */
+ (void)LFStickerViewDeactivated;
/** 激活选中的贴图 */
- (void)activeSelectStickerView;
/** 删除选中贴图 */
- (void)removeSelectStickerView;
/** 获取选中贴图的内容 */
- (LFStickerItem *)getSelectStickerItem;
/** 更改选中贴图内容 */
- (void)changeSelectStickerItem:(LFStickerItem *)item;
/** create sticker */
- (void)createStickerItem:(LFStickerItem *)item;
/** 最小缩放率 默认0.2 */
@property (nonatomic, assign) CGFloat minScale;
/** 最大缩放率 默认3.0 */
@property (nonatomic, assign) CGFloat maxScale;
/** 显示界面的缩放率,例如在UIScrollView上显示,scrollView放大了5倍,movingView的视图控件会显得较大,这个属性是适配当前屏幕的比例调整控件大小 */
@property (nonatomic, assign) CGFloat screenScale;
/** 是否启用(移动或点击) */
@property (nonatomic, readonly, getter=isEnable) BOOL enable;
/** 数据 */
@property (nonatomic, strong) NSDictionary *data;
/** 点击回调视图 */
@property (nonatomic, copy) void(^tapEnded)(LFStickerItem *item, BOOL isActive);
@property (nonatomic, copy) BOOL(^moveCenter)(CGRect rect);
@end
//
// LFStickerView.m
// LFImagePickerController
//
// Created by LamTsanFeng on 2017/2/24.
// Copyright © 2017年 LamTsanFeng. All rights reserved.
//
#import "LFStickerView.h"
#import "LFMovingView.h"
#import "UIView+LFMEFrame.h"
NSString *const kLFStickerViewData_movingView = @"LFStickerViewData_movingView";
NSString *const kLFStickerViewData_movingView_content = @"LFStickerViewData_movingView_content";
NSString *const kLFStickerViewData_movingView_center = @"LFStickerViewData_movingView_center";
NSString *const kLFStickerViewData_movingView_scale = @"LFStickerViewData_movingView_scale";
NSString *const kLFStickerViewData_movingView_rotation = @"LFStickerViewData_movingView_rotation";
@interface LFStickerView ()
@property (nonatomic, weak) LFMovingView *selectMovingView;
@property (nonatomic, assign, getter=isHitTestSubView) BOOL hitTestSubView;
@end
@implementation LFStickerView
+ (void)LFStickerViewDeactivated
{
[LFMovingView setActiveEmoticonView:nil];
}
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self customInit];
}
return self;
}
- (void)customInit
{
self.userInteractionEnabled = YES;
self.clipsToBounds = YES;
_screenScale = 1.f;
_minScale = .2f;
_maxScale = 3.f;
}
#pragma mark - 解除响应事件
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
UIView *view = [super hitTest:point withEvent:event];
self.hitTestSubView = [view isDescendantOfView:self];
return (view == self ? nil : view);
}
- (BOOL)isEnable
{
return self.isHitTestSubView && self.selectMovingView.isActive;
}
- (void)setTapEnded:(void (^)(LFStickerItem *, BOOL))tapEnded
{
_tapEnded = tapEnded;
for (LFMovingView *subView in self.subviews) {
if ([subView isKindOfClass:[LFMovingView class]]) {
if (tapEnded) {
__weak typeof(self) weakSelf = self;
[subView setTapEnded:^(LFMovingView *view) {
weakSelf.selectMovingView = view;
weakSelf.tapEnded(view.item, view.isActive);
}];
} else {
[subView setTapEnded:nil];
}
}
}
}
- (void)setMoveCenter:(BOOL (^)(CGRect))moveCenter
{
_moveCenter = moveCenter;
for (LFMovingView *subView in self.subviews) {
if ([subView isKindOfClass:[LFMovingView class]]) {
if (moveCenter) {
__weak typeof(self) weakSelf = self;
[subView setMoveCenter:^BOOL (CGRect rect) {
return weakSelf.moveCenter(rect);
}];
} else {
[subView setMoveCenter:nil];
}
}
}
}
/** 激活选中的贴图 */
- (void)activeSelectStickerView
{
[LFMovingView setActiveEmoticonView:self.selectMovingView];
}
/** 删除选中贴图 */
- (void)removeSelectStickerView
{
[self.selectMovingView removeFromSuperview];
}
/** 获取选中贴图的内容 */
- (LFStickerItem *)getSelectStickerItem
{
return self.selectMovingView.item;
}
/** 更改选中贴图内容 */
- (void)changeSelectStickerItem:(LFStickerItem *)item
{
self.selectMovingView.item = item;
}
/** 创建可移动视图 */
- (LFMovingView *)createBaseMovingView:(LFStickerItem *)item active:(BOOL)active
{
LFMovingView *movingView = [[LFMovingView alloc] initWithItem:item];
/** 屏幕中心 */
movingView.center = [self convertPoint:[UIApplication sharedApplication].keyWindow.center fromView:(UIView *)[UIApplication sharedApplication].keyWindow];
[self updateMovingView:movingView];
[self addSubview:movingView];
if (active) {
[LFMovingView setActiveEmoticonView:movingView];
}
__weak typeof(self) weakSelf = self;
if (self.tapEnded) {
[movingView setTapEnded:^(LFMovingView * _Nonnull view) {
weakSelf.selectMovingView = view;
weakSelf.tapEnded(view.item, view.isActive);
}];
}
if (self.moveCenter) {
[movingView setMoveCenter:^BOOL (CGRect rect) {
return weakSelf.moveCenter(rect);
}];
}
return movingView;
}
- (void)createStickerItem:(LFStickerItem *)item
{
LFMovingView *movingView = [self createBaseMovingView:item active:YES];
CGFloat ratio = 0.5;
CGFloat scale = MIN( (ratio * [UIScreen mainScreen].bounds.size.width) / movingView.view.frame.size.width, (ratio * [UIScreen mainScreen].bounds.size.height) / movingView.view.frame.size.height);
[movingView setScale:scale/self.screenScale];
// NSLog(@"minScale:%f, maxScale:%f, scale:%f", movingView.minScale, movingView.maxScale, movingView.scale);
self.selectMovingView = movingView;
}
- (void)updateMovingView:(LFMovingView *)movingView
{
/** 最小缩放率 */
movingView.minScale = self.minScale;
/** 最大缩放率 */
movingView.maxScale = self.maxScale;
/** 屏幕缩放率 */
movingView.screenScale = self.screenScale;
}
- (void)setScreenScale:(CGFloat)screenScale
{
if (screenScale > 0) {
_screenScale = screenScale;
for (LFMovingView *subView in self.subviews) {
if ([subView isKindOfClass:[LFMovingView class]]) {
subView.screenScale = screenScale;
}
}
}
}
#pragma mark - 数据
- (NSDictionary *)data
{
NSMutableArray *movingDatas = [@[] mutableCopy];
for (LFMovingView *view in self.subviews) {
if ([view isKindOfClass:[LFMovingView class]]) {
[movingDatas addObject:@{kLFStickerViewData_movingView_content:view.item
, kLFStickerViewData_movingView_scale:@(view.scale)
, kLFStickerViewData_movingView_rotation:@(view.rotation)
, kLFStickerViewData_movingView_center:[NSValue valueWithCGPoint:view.center]
}];
}
}
if (movingDatas.count) {
return @{kLFStickerViewData_movingView:[movingDatas copy]};
}
return nil;
}
- (void)setData:(NSDictionary *)data
{
NSArray *movingDatas = data[kLFStickerViewData_movingView];
if (movingDatas.count) {
for (NSDictionary *movingData in movingDatas) {
LFStickerItem *item = movingData[kLFStickerViewData_movingView_content];
CGFloat scale = [movingData[kLFStickerViewData_movingView_scale] floatValue];
CGFloat rotation = [movingData[kLFStickerViewData_movingView_rotation] floatValue];
CGPoint center = [movingData[kLFStickerViewData_movingView_center] CGPointValue];
LFMovingView *view = [self createBaseMovingView:item active:NO];
[view setScale:scale rotation:rotation];
view.center = center;
}
}
}
@end
//
// YJBezierPath.h
// TestOC
//
// Created by 李亚军 on 2017/2/8.
// Copyright © 2017年 zyyj. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface YJBezierPath : UIBezierPath
//画笔的颜色
@property (nonatomic,copy) UIColor *lineColor;
//是否是橡皮擦
@property (nonatomic,assign) BOOL isErase;
@end
//
// YJBezierPath.m
// TestOC
//
// Created by 李亚军 on 2017/2/8.
// Copyright © 2017年 zyyj. All rights reserved.
//
#import "YJBezierPath.h"
@implementation YJBezierPath
@end
//
// LFClipToolbar.h
// LFImagePickerController
//
// Created by LamTsanFeng on 2017/4/13.
// Copyright © 2017年 LamTsanFeng. All rights reserved.
//
#import <UIKit/UIKit.h>
@protocol LFClipToolbarDelegate, LFEditToolbarDataSource;
@interface LFClipToolbar : UIView
/** 代理 */
@property (nonatomic, weak) id<LFClipToolbarDelegate> delegate;
@property (nonatomic, weak) id<LFEditToolbarDataSource> dataSource;
/** 开启重置按钮 default NO */
@property (nonatomic, assign) BOOL enableReset;
/** 选中长宽比例按钮 default NO */
@property (nonatomic, assign) BOOL selectAspectRatio;
@property (nonatomic, readonly) CGRect clickViewRect;
@end
@protocol LFClipToolbarDelegate <NSObject>
/** 取消 */
- (void)lf_clipToolbarDidCancel:(LFClipToolbar *)clipToolbar;
/** 完成 */
- (void)lf_clipToolbarDidFinish:(LFClipToolbar *)clipToolbar;
/** 重置 */
- (void)lf_clipToolbarDidReset:(LFClipToolbar *)clipToolbar;
/** 旋转 */
- (void)lf_clipToolbarDidRotate:(LFClipToolbar *)clipToolbar;
/** 长宽比例 */
- (void)lf_clipToolbarDidAspectRatio:(LFClipToolbar *)clipToolbar;
@end
@protocol LFEditToolbarDataSource <NSObject>
@optional
/** 允许旋转 默认YES */
- (BOOL)lf_clipToolbarCanRotate:(LFClipToolbar *)clipToolbar;
/** 允许长宽比例 默认YES */
- (BOOL)lf_clipToolbarCanAspectRatio:(LFClipToolbar *)clipToolbar;
@end
//
// LFEditCollectionView.h
// SafeAreaTest
//
// Created by TsanFeng Lam on 2017/11/16.
// Copyright © 2017年 TsanFeng Lam. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
typedef NSString * _Nonnull (^LFEditCollectionViewDequeueReusableCellBlock)(NSIndexPath * _Nonnull indexPath);
typedef void (^LFEditCollectionViewCellConfigureBlock)(NSIndexPath * _Nonnull indexPath, id _Nonnull item, UICollectionViewCell * _Nonnull cell);
typedef void (^LFEditCollectionViewDidSelectItemAtIndexPathBlock)(NSIndexPath * _Nonnull indexPath, id _Nonnull item);
@protocol LFEditCollectionViewDelegate;
@interface LFEditCollectionView : UIView
@property (nonatomic, strong) NSArray <NSArray *> *dataSources;
- (void)callbackCellIdentifier:(LFEditCollectionViewDequeueReusableCellBlock)aCellIdentifier
configureCell:(LFEditCollectionViewCellConfigureBlock)aConfigureCell
didSelectItemAtIndexPath:(LFEditCollectionViewDidSelectItemAtIndexPathBlock)aDidSelectItemAtIndexPath;
#pragma mark - UICollectionView
@property (nonatomic, strong) UICollectionViewLayout * _Nullable collectionViewLayout;
@property(nonatomic,getter=isPagingEnabled) BOOL pagingEnabled __TVOS_PROHIBITED;// default NO. if YES, stop on multiples of view bounds
@property(nonatomic) BOOL showsHorizontalScrollIndicator; // default YES. show indicator while we are tracking. fades out after tracking
@property(nonatomic) BOOL showsVerticalScrollIndicator; // default YES. show indicator while we are tracking. fades out after tracking
- (void)registerClass:(nullable Class)cellClass forCellWithReuseIdentifier:(NSString *)identifier;
- (void)registerNib:(nullable UINib *)nib forCellWithReuseIdentifier:(NSString *)identifier;
- (void)scrollToItemAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UICollectionViewScrollPosition)scrollPosition animated:(BOOL)animated;
- (nullable UICollectionViewCell *)cellForItemAtIndexPath:(NSIndexPath *)indexPath;
#pragma mark - UICollectionViewFlowLayout
@property (nonatomic) CGFloat minimumLineSpacing;
@property (nonatomic) CGFloat minimumInteritemSpacing;
@property (nonatomic) CGSize itemSize;
@property (nonatomic) CGSize estimatedItemSize NS_AVAILABLE_IOS(8_0); // defaults to CGSizeZero - setting a non-zero size enables cells that self-size via -preferredLayoutAttributesFittingAttributes:
@property (nonatomic) UICollectionViewScrollDirection scrollDirection; // default is UICollectionViewScrollDirectionVertical
@property (nonatomic) CGSize headerReferenceSize;
@property (nonatomic) CGSize footerReferenceSize;
@property (nonatomic) UIEdgeInsets sectionInset;
#pragma mark - UIScrollView
@property(nonatomic) BOOL bounces; // default YES. if YES, bounces past edge of content and back again
@property(nullable,nonatomic,weak) id<LFEditCollectionViewDelegate> delegate; // default nil. weak reference
- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated; // animate at constant velocity to new offset
- (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated; // scroll so rect is just visible (nearest edges). nothing if rect completely visible
@end
@protocol LFEditCollectionViewDelegate<NSObject>
@optional
- (void)scrollViewDidScroll:(UIScrollView *)scrollView; // any offset changes
// called on start of dragging (may require some time and or distance to move)
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView;
// called on finger up if the user dragged. velocity is in points/millisecond. targetContentOffset may be changed to adjust where the scroll view comes to rest
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset NS_AVAILABLE_IOS(5_0);
// called on finger up if the user dragged. decelerate is true if it will continue moving afterwards
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate;
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView; // called on finger up as we are moving
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView; // called when scroll view grinds to a halt
@end
NS_ASSUME_NONNULL_END
//
// LFEditToolbar.h
// LFImagePickerController
//
// Created by LamTsanFeng on 2017/3/14.
// Copyright © 2017年 LamTsanFeng. All rights reserved.
//
#import <UIKit/UIKit.h>
typedef NS_ENUM(NSUInteger, LFEditToolbarType) {
/** 绘画 */
LFEditToolbarType_draw = 1 << 0,
/** 贴图 */
LFEditToolbarType_sticker = 1 << 1,
/** 文本 */
LFEditToolbarType_text = 1 << 2,
/** 模糊 */
LFEditToolbarType_splash = 1 << 3,
/** 修剪 */
LFEditToolbarType_crop = 1 << 4,
/** 音频 */
LFEditToolbarType_audio = 1 << 5,
/** 剪辑 */
LFEditToolbarType_clip = 1 << 6,
/** 滤镜 */
LFEditToolbarType_filter = 1 << 7,
/** 速率 */
LFEditToolbarType_rate = 1 << 8,
/** 橡皮擦 */
LFEditToolbarType_eraser = 1 << 9,
/** 所有 */
LFEditToolbarType_All = ~0UL,
};
@protocol LFEditToolbarDelegate;
@interface LFEditToolbar : UIView
- (instancetype)initWithType:(LFEditToolbarType)type;
@property (nonatomic, weak) id<LFEditToolbarDelegate> delegate;
/** 播放速率 */
@property (nonatomic, assign) float rate;
/** 当前激活主菜单 return -1 没有激活 */
- (NSUInteger)mainSelectAtIndex;
/** 允许撤销 */
- (void)setRevokeAtIndex:(NSUInteger)index;
/** 获取拾色器的颜色 */
- (NSArray <UIColor *>*)drawSliderColors;
- (UIColor *)drawSliderCurrentColor;
/** 设置绘画拾色器默认颜色 */
- (void)setDrawSliderColor:(UIColor *)color;
- (void)setDrawSliderColorAtIndex:(NSUInteger)index;
/** 设置默认模糊类型 */
- (void)setSplashIndex:(NSUInteger)index;
/** 选择主菜单的功能类型(会触发代理) */
- (void)selectMainMenuIndex:(NSUInteger)index;
@end
@protocol LFEditToolbarDelegate <NSObject>
/**
主菜单点击事件
@param editToolbar self
@param index 坐标(第几个按钮)
*/
- (void)lf_editToolbar:(LFEditToolbar *)editToolbar mainDidSelectAtIndex:(NSUInteger)index;
/** 二级菜单点击事件-撤销 */
- (void)lf_editToolbar:(LFEditToolbar *)editToolbar subDidRevokeAtIndex:(NSUInteger)index;
/** 二级菜单点击事件-按钮 */
- (void)lf_editToolbar:(LFEditToolbar *)editToolbar subDidSelectAtIndex:(NSIndexPath *)indexPath;
/** 撤销允许权限获取 */
- (BOOL)lf_editToolbar:(LFEditToolbar *)editToolbar canRevokeAtIndex:(NSUInteger)index;
/** 二级菜单滑动事件-绘画 */
- (void)lf_editToolbar:(LFEditToolbar *)editToolbar drawColorDidChange:(UIColor *)color;
@optional
/** 二级菜单滑动事件-速率 */
- (void)lf_editToolbar:(LFEditToolbar *)editToolbar rateDidChange:(float)value;
@end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment