RSKImageCropper

2025-12-11 0 750

RSKImageCropper

iOS的图像农作物类似于Contacts App中的iOS,并支持景观取向。

安装

RSKImageCropper需要iOS 12.0或更高版本。

使用Swift Package Manager

  1. 要将RSKImageCropper软件包添加到您的Xcode项目中,请选择“文件> swift软件包”>“添加软件包依赖关系”并输入存储库URL。

     https://g*it*hu*b.com/ruslanskorb/RSKImageCropper.git
    

使用Cocoapods

  1. 将POD RSKImageCropper添加到您的podfile中。

    pod \' RSKImageCropper \'
    
  2. 从终端运行POD安装,然后打开您的应用程序的.xcworkspace文件以启动Xcode。

  3. 导入RSKImageCropper .h标头。通常,这应该写为#import < RSKImageCropper / RSKImageCropper .h>

使用迦太基

  1. 将Ruslanskorb/ RSKImageCropper项目添加到您的卡特文件中。

    github \"ruslanskorb/ RSKImageCropper \"
    
  2. 运行迦太基更新,然后按照将iOS和/或MAC框架添加到项目中所需的其他步骤。

  3. 导入RSKImageCropper框架/模块。

    • 使用模块:@Import RSKImageCropper
    • 没有模块:#import < RSKImageCropper / RSKImageCropper .h>

基本用法

导入类标题。

RSKImageCropper .h>\”>

# import < RSKImageCropper / RSKImageCropper .h >

只需创建一个用于图像裁剪的视图控制器并设置委托。

- ( IBAction )onButtonTouch:(UIButton *)sender
{
    UIImage *image = [UIImage imageNamed: @\" image \" ];
    RSKImageCropViewController *imageCropViewController = [[RSKImageCropViewController alloc ] initWithImage: image];
    imageCropViewController. delegate = self;
    [ self .navigationController pushViewController: imageCropViewController animated: YES ];
}

代表

rskimagecropviewControllerDelegate提供了三种代表方法。要使用它们,请在视图控制器中实现代表。

 @interface ViewController () <RSKImageCropViewControllerDelegate>

然后实现委托功能。

 // Crop image has been canceled.
- ( void )imageCropViewControllerDidCancelCrop:(RSKImageCropViewController *)controller
{
    [ self .navigationController popViewControllerAnimated: YES ];
}

// The original image has been cropped. Additionally provides a rotation angle used to produce image.
- ( void )imageCropViewController:(RSKImageCropViewController *)controller
                   didCropImage:(UIImage *)croppedImage
                  usingCropRect:(CGRect)cropRect
                  rotationAngle:(CGFloat)rotationAngle
{
    self. imageView . image = croppedImage;
    [ self .navigationController popViewControllerAnimated: YES ];
}

// The original image will be cropped.
- ( void )imageCropViewController:(RSKImageCropViewController *)controller
                  willCropImage:(UIImage *)originalImage
{
    // Use when `applyMaskToCroppedImage` set to YES.
    [SVProgressHUD show ];
}

数据源

rskimagecropviewControllerDatasource提供了三种数据源方法。方法ImageCropviewControllerCustomMaskRect:向掩模的自定义RECT询问数据源。方法ImageCropviewControllerCustommaskPath:向数据源询问掩码的自定义路径。方法ImageCropviewControllerCustommovementRect:向数据源询问可以移动图像的自定义RECT。要使用它们,请在视图控制器中实现数据源。

 @interface ViewController () <RSKImageCropViewControllerDataSource>

然后实现数据源功能。

 // Returns a custom rect for the mask.
- (CGRect)imageCropViewControllerCustomMaskRect:(RSKImageCropViewController *)controller
{
    CGSize aspectRatio = CGSizeMake ( 16 . 0f , 9 . 0f );
    
    CGFloat viewWidth = CGRectGetWidth (controller. view . frame );
    CGFloat viewHeight = CGRectGetHeight (controller. view . frame );
    
    CGFloat maskWidth;
    if ([controller isPortraitInterfaceOrientation ]) {
        maskWidth = viewWidth;
    } else {
        maskWidth = viewHeight;
    }
    
    CGFloat maskHeight;
    do {
        maskHeight = maskWidth * aspectRatio. height / aspectRatio. width ;
        maskWidth -= 1 . 0f ;
    } while (maskHeight != floor (maskHeight));
    maskWidth += 1 . 0f ;
    
    CGSize maskSize = CGSizeMake (maskWidth, maskHeight);
    
    CGRect maskRect = CGRectMake ((viewWidth - maskSize. width ) * 0 . 5f ,
                                 (viewHeight - maskSize. height ) * 0 . 5f ,
                                 maskSize. width ,
                                 maskSize. height );
    
    return maskRect;
}

// Returns a custom path for the mask.
- (UIBezierPath *)imageCropViewControllerCustomMaskPath:(RSKImageCropViewController *)controller
{
    CGRect rect = controller. maskRect ;
    CGPoint point1 = CGPointMake ( CGRectGetMinX (rect), CGRectGetMaxY (rect));
    CGPoint point2 = CGPointMake ( CGRectGetMaxX (rect), CGRectGetMaxY (rect));
    CGPoint point3 = CGPointMake ( CGRectGetMaxX (rect), CGRectGetMinY (rect));
    CGPoint point4 = CGPointMake ( CGRectGetMinX (rect), CGRectGetMinY (rect));
    
    UIBezierPath *rectangle = [UIBezierPath bezierPath ];
    [rectangle moveToPoint: point1];
    [rectangle addLineToPoint: point2];
    [rectangle addLineToPoint: point3];
    [rectangle addLineToPoint: point4];
    [rectangle closePath ];
    
    return rectangle;
}

// Returns a custom rect in which the image can be moved.
- (CGRect)imageCropViewControllerCustomMovementRect:(RSKImageCropViewController *)controller
{
    if (controller. rotationAngle == 0 ) {
        return controller. maskRect ;
    } else {
        CGRect maskRect = controller. maskRect ;
        CGFloat rotationAngle = controller. rotationAngle ;
        
        CGRect movementRect = CGRectZero;
        
        movementRect. size . width = CGRectGetWidth (maskRect) * fabs ( cos (rotationAngle)) + CGRectGetHeight (maskRect) * fabs ( sin (rotationAngle));
        movementRect. size . height = CGRectGetHeight (maskRect) * fabs ( cos (rotationAngle)) + CGRectGetWidth (maskRect) * fabs ( sin (rotationAngle));
        
        movementRect. origin . x = CGRectGetMinX (maskRect) + ( CGRectGetWidth (maskRect) - CGRectGetWidth (movementRect)) * 0 . 5f ;
        movementRect. origin . y = CGRectGetMinY (maskRect) + ( CGRectGetHeight (maskRect) - CGRectGetHeight (movementRect)) * 0 . 5f ;
        
        movementRect. origin . x = floor ( CGRectGetMinX (movementRect));
        movementRect. origin . y = floor ( CGRectGetMinY (movementRect));
        movementRect = CGRectIntegral (movementRect);
        
        return movementRect;
    }
}

即将推出

  • 如果您想请求新功能,请随时提出问题。

演示

在Xcode中构建并运行RSKImageCropper示例项目,以查看RSKImageCropper的作用。玩得开心。分叉并发送拉请请求。找出自定义的钩子。

隐私

RSKImageCropper不需要隐私清单。根据苹果收到的信息,我们应该避免在我们的框架中添加空的隐私清单。

接触

Ruslan Skorb

  • http://*gi*thub.*com/ruslanskorb
  • http://twitt**e*r.com/ruslanskorb
  • ruslan.skorb@gmail.com

执照

该项目可根据麻省理工学院许可获得。有关更多信息,请参见许可证文件。通过链接到项目页面来归因。

下载源码

通过命令行克隆项目:

git clone https://github.com/ruslanskorb/RSKImageCropper.git

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

申明:本文由第三方发布,内容仅代表作者观点,与本网站无关。对本文以及其中全部或者部分内容的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。本网发布或转载文章出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,也不代表本网对其真实性负责。

左子网 建站资源 RSKImageCropper https://www.zuozi.net/35119.html

nvimdots
上一篇: nvimdots
Doodle
下一篇: Doodle
常见问题
  • 1、自动:拍下后,点击(下载)链接即可下载;2、手动:拍下后,联系卖家发放即可或者联系官方找开发者发货。
查看详情
  • 1、源码默认交易周期:手动发货商品为1-3天,并且用户付款金额将会进入平台担保直到交易完成或者3-7天即可发放,如遇纠纷无限期延长收款金额直至纠纷解决或者退款!;
查看详情
  • 1、描述:源码描述(含标题)与实际源码不一致的(例:货不对板); 2、演示:有演示站时,与实际源码小于95%一致的(但描述中有”不保证完全一样、有变化的可能性”类似显著声明的除外); 3、发货:不发货可无理由退款; 4、安装:免费提供安装服务的源码但卖家不履行的; 5、收费:价格虚标,额外收取其他费用的(但描述中有显著声明或双方交易前有商定的除外); 6、其他:如质量方面的硬性常规问题BUG等。 注:经核实符合上述任一,均支持退款,但卖家予以积极解决问题则除外。
查看详情
  • 1、左子会对双方交易的过程及交易商品的快照进行永久存档,以确保交易的真实、有效、安全! 2、左子无法对如“永久包更新”、“永久技术支持”等类似交易之后的商家承诺做担保,请买家自行鉴别; 3、在源码同时有网站演示与图片演示,且站演与图演不一致时,默认按图演作为纠纷评判依据(特别声明或有商定除外); 4、在没有”无任何正当退款依据”的前提下,商品写有”一旦售出,概不支持退款”等类似的声明,视为无效声明; 5、在未拍下前,双方在QQ上所商定的交易内容,亦可成为纠纷评判依据(商定与描述冲突时,商定为准); 6、因聊天记录可作为纠纷评判依据,故双方联系时,只与对方在左子上所留的QQ、手机号沟通,以防对方不承认自我承诺。 7、虽然交易产生纠纷的几率很小,但一定要保留如聊天记录、手机短信等这样的重要信息,以防产生纠纷时便于左子介入快速处理。
查看详情

相关文章

猜你喜欢
发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务