GithubHelp home page GithubHelp logo

timoliver / tocropviewcontroller Goto Github PK

View Code? Open in Web Editor NEW
4.6K 87.0 920.0 8.56 MB

A view controller for iOS that allows users to crop portions of UIImage objects

Home Page: http://www.timoliver.com.au/2015/06/21/tocropviewcontroller-an-open-source-image-cropper-for-ios/

License: MIT License

Ruby 2.58% Objective-C 82.65% Swift 14.77%
cropper image image-processing ios cocoapods viewcontroller crop-image swift podfile crop

tocropviewcontroller's Introduction

TOCropViewController

CI Version Carthage compatible GitHub license Platform

TOCropViewController is an open-source UIViewController subclass to crop out sections of UIImage objects, as well as perform basic rotations. It is excellent for things like editing profile pictures, or sharing parts of a photo online. It has been designed with the iOS Photos app editor in mind, and as such, behaves in a way that should already feel familiar to users of iOS.

For Swift developers, CropViewController is a Swift wrapper that completely encapsulates TOCropViewController and provides a much more native, Swiftier interface.

Proudly powering apps by

Looking for something more? If TOCropViewController doesn't meet your exact requirements, please consider IMG.LY with video editing and photo filter capabilities instead! (Disclaimer: Affiliate Link)

Features

  • Crop images by dragging the edges of a grid overlay.
  • Optionally, crop circular copies of images.
  • Rotate images in 90-degree segments.
  • Clamp the crop box to a specific aspect ratio.
  • A reset button to completely undo all changes.
  • iOS 7/8 translucency to make it easier to view the cropped region.
  • The choice of having the controller return the cropped image to a delegate, or immediately pass it to a UIActivityViewController.
  • A custom animation and layout when the device is rotated to landscape mode.
  • Custom 'opening' and 'dismissal' animations.
  • Localized in 28 languages.

System Requirements

iOS 11.0 or above

Installation

CocoaPods

Objective-C

Add the following to your Podfile:

pod 'TOCropViewController'

Swift

Add the following to your Podfile:

pod 'CropViewController'
Swift Package Manager

Add the following to your Package.swift:

dependencies: [
  // ...
  .package(url: "https://github.com/TimOliver/TOCropViewController.git"),
],
Carthage
  1. Add the following to your Cartfile:
github "TimOliver/TOCropViewController"
  1. Run carthage update

  2. From the Carthage/Build folder, import one of the two frameworks into your Xcode project. For Objective-C projects, import just TOCropViewController.framework and for Swift, import CropViewController.framework instead. Each framework is separate; you do not need to import both.

  3. Follow the remaining steps on Getting Started with Carthage to finish integrating the framework.

Manual Installation

All of the necessary source and resource files for TOCropViewController are in Objective-C/TOCropViewController, and all of the necessary Swift files are in Swift/CropViewController.

For Objective-C projects, copy just the TOCropViewController directory to your Xcode project. For Swift projects, copy both TOCropViewController and CropViewController to your project.

Examples

Using TOCropViewController is very straightforward. Simply create a new instance passing the UIImage object you wish to crop, and then present it modally on the screen.

While TOCropViewController prefers to be presented modally, it can also be pushed to a UINavigationController stack.

For a complete working example, check out the sample apps included in this repo.

Basic Implementation

Swift

func presentCropViewController() {
  let image: UIImage = ... //Load an image
  
  let cropViewController = CropViewController(image: image)
  cropViewController.delegate = self
  present(cropViewController, animated: true, completion: nil)
}

func cropViewController(_ cropViewController: CropViewController, didCropToImage image: UIImage, withRect cropRect: CGRect, angle: Int) {
        // 'image' is the newly cropped version of the original image
    }

Objective-C

- (void)presentCropViewController
{
  UIImage *image = ...; // Load an image
  
  TOCropViewController *cropViewController = [[TOCropViewController alloc] initWithImage:image];
  cropViewController.delegate = self;
  [self presentViewController:cropViewController animated:YES completion:nil];
}

- (void)cropViewController:(TOCropViewController *)cropViewController didCropToImage:(UIImage *)image withRect:(CGRect)cropRect angle:(NSInteger)angle
{
  // 'image' is the newly cropped version of the original image
}

Similar to many UIKit UIViewController subclasses, like MFMailComposeViewController, the class responsible for presenting view controller should also take care of dismissing it upon cancellation. To dismiss TOCropViewController, implement the cropViewController:didFinishCancelled: delegate method, and call dismissViewController:animated: from there.

Making a Circular Cropped Image

Swift

func presentCropViewController() {
    var image: UIImage? // Load an image
    let cropViewController = CropViewController(croppingStyle: .circular, image: image)
    cropViewController.delegate = self
    self.present(cropViewController, animated: true, completion: nil)
}

func cropViewController(_ cropViewController: TOCropViewController?, didCropToCircularImage image: UIImage?, with cropRect: CGRect, angle: Int) {
    // 'image' is the newly cropped, circular version of the original image
}

Objective-C

- (void)presentCropViewController
{
UIImage *image = ...; // Load an image

TOCropViewController *cropViewController = [[TOCropViewController alloc] initWithCroppingStyle:TOCropViewCroppingStyleCircular image:image];
cropViewController.delegate = self;
[self presentViewController:cropViewController animated:YES completion:nil];
}

- (void)cropViewController:(TOCropViewController *)cropViewController didCropToCircularImage:(UIImage *)image withRect:(CGRect)cropRect angle:(NSInteger)angle
{
// 'image' is the newly cropped, circular version of the original image
}
Sharing Cropped Images Via a Share Sheet

Swift

func presentCropViewController() {
    var image: UIImage? // Load an image
    let cropViewController = CropViewController(image: image)
    cropViewController.showActivitySheetOnDone = true
    self.present(cropViewController, animated: true, completion: nil)
}

Objective-C

- (void)presentCropViewController
{
  UIImage *image = ...; // Load an image
  
  TOCropViewController *cropViewController = [[TOCropViewController alloc] initWithImage:image];
  cropViewController.showActivitySheetOnDone = YES;
  [self presentViewController:cropViewController animated:YES completion:nil];
}
Presenting With a Custom Animation

Optionally, TOCropViewController also supports a custom presentation animation where an already-visible copy of the image will zoom in to fill the screen.

Swift

func presentCropViewController() {
    var image: UIImage? // Load an image
    var imageView = UIImageView(image: image)
    var frame: CGRect = view.convert(imageView.frame, to: view)
    
    let cropViewController = CropViewController(image: image)
    cropViewController.delegate = self
    self.present(cropViewController, animated: true, completion: nil)
    cropViewController.presentAnimated(fromParentViewController: self, fromFrame: frame, completion: nil)
}

Objective-C

- (void)presentCropViewController
{
  UIImage *image = ...;
  UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
  CGRect frame = [self.view convertRect:imageView.frame toView:self.view];
  
  TOCropViewController *cropViewController = [[TOCropViewController alloc] initWithImage:image];
  cropViewController.delegate = self;
  [self presentViewController:cropViewController animated:YES completion:nil];
  [cropViewController presentAnimatedFromParentViewController:self fromFrame:frame completion:nil];
}

Architecture of TOCropViewController

While traditional cropping UI implementations will usually just have a dimming view with a square hole cut out of the middle, TOCropViewController goes about its implementation a little differently.

Since there are two views that are overlaid over the image (A dimming view and a translucency view), trying to cut a hole open in both of them would be rather complex. Instead, an image view is placed in a scroll view in the background, and a copy of the image view is placed on top, inside a container view that is clipped to the designated cropping size. The size and position of the foreground image is then made to match the background view, creating the illusion that there is a hole in the dimming views, and minimising the number of views onscreen.

Credits

TOCropViewController was originally created by Tim Oliver as a component for iComics, a comic reader app for iOS.

Thanks also goes to TOCropViewController's growing list of contributors!

iOS Device mockups used in the screenshot created by Pixeden.

License

TOCropViewController is licensed under the MIT License, please see the LICENSE file.

tocropviewcontroller's People

Contributors

anonymouz4 avatar chiformihai avatar cupnoodle avatar dependabot[bot] avatar grigaci avatar huang-kun avatar jboulter11 avatar karlosq avatar kekearif avatar kennyevo avatar librecht-official avatar mekjaer avatar michalsrutek avatar milanrancic avatar mono0926 avatar noppefoxwolf avatar oscargorog avatar rastislavmirek avatar rockylive avatar shubham14896 avatar simone-gasparini avatar siong1987 avatar timoliver avatar tristangrichard avatar viikufa avatar woxtu avatar xd-ci avatar yesleon avatar yudiz-mahavirsinh avatar zachorr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tocropviewcontroller's Issues

Disabling vertical or horizontal cropping

Hi Tim

First of all fantastic library, I have used a few cropping libraries and this one is by far the best. Great job!

I was wondering if it is possible to restrict the cropping to either horizontal or vertical? I want all my images to be the width of the image and users only able to increase or decrease the height of the image.

Any help would be very appreciated.

Simon Smiley-Andrews

Aspect Ratio Constraint

Setting the aspect ratio does not properly work. In my case I was trying to obtain an exact 2:3 ratio

I'm logging the cropBoxFrame just before cropping the image, but the ratio of it's size is no longer 2:3, resulting in a cropped image that is not in the correct size.

I'll probably investigate further, for now I'm calling several times setAspectLockEnabledWithAspectRatio. Its extremely ugly, but eventually leads to a correct cropBoxFrame.

crashed in iPhone 6

hi tim
i have implemented your code .it was superrr.i have faced this issue in iphone 6 .
Received memory warning.
Communications error: <OS_xpc_error: <error: 0x19b382a80> { count = 1, contents =
"XPCErrorDescription" => <string: 0x19b382e78> { length = 22, contents = "Connection interrupted" }
}>
Connection to assetsd was interrupted or assetsd died
Terminating since there is no system app.

Rotate wheel

It would be nice to implement a rotate wheel, every time i implement crop in my app, all crop library never have rotate wheel and also it's really hard to edit it to add this possibility.

If you could add it, your crop lib, will be the better on Github.

Problem with localization while installing TOCropViewController with cocoapods

Currently I am adding Arabic localization and faced with the problem, that UI elements aren't translating to different language.

9c17c4e4-cff5-11e5-97cd-9989f4a5ef93

screenshot was made on iPod touch with iOS 9.2.1, current language is Arabic, status bar is flipped and title of navigation bar is localized, but buttons on TOCropToolbar aren't localized.

This issue might be connected to one, that has been closed #30 .
In your screenshot in that issue did you launch your project with cocoa pods or from the example in your repository?
Because if I launch project from your example localization works as expected

p.s. And by the way, thanks a lot for the library.

When ratio is locked, only the picture should rotate

Enhancement request:
I'm using this library for profile pictures and it would be nice if the ratio did not rotate with picture.
So when I fix it to 3:4 and rotate the picture it remains at 3:4 and not 4:3.

How to build

How to build your project. with an error when open the downloaded project

Set Cropper Minimum Size

Hello,

Thank you for this amazing cropper code.
I have one requirement where I need to limit the cropper to certain height and width.
I need to set a thumbnail from an image.The image could be tall(1400x600 image resolution from the gallery) or wide(600x1400 image resolution from the gallery), but the thumbnail should be in 4:3 ratio(of image resolution) only.So cropper should be in 4:3 with minimum height and width of 400 x 300.
If a user selects an image is of size 2154x1616, the cropper should let user crop until image size become 400x300.If a user is trying to crop an image even after the image is 400x300, cropper should not let user.
Is there any way in current code to do this?

Italian localization fix

"Done" = "Fatto";
"Cancel" = "Annulla";
"Reset" = "Ripristina";
"Original" = "Originale";
"Square" = "Quadrato";

How can I set limit output size

Hi.

Thank for your library. I'm using it.

Please let's me know how can I set image output limit (maximum).

For example: My ImageView frame is 600x900. So I just want output close to that size as possible.
It's will make my app more lightweight.

Thanh.

Issue with resetting the image

Hi Tim,

I have implemented the crop view and it works perfectly fine. Is there a way to reset the image. I'm trying to incorporate filters into the crop view your suggested. But filters are implemented fine, but the applied filters are not shown in the imageview. I'm not able to reset the imageview which the cropview has already used.

Can you please help me out ? How image can be reset in your code or is there any way to do so ?

Image without cropping show incorrect

Hardware

iPhone 5
iOS 9.3.1
TOCropViewController (1.2.9)

Expected Behavior

When I pick some image and press Done without any cropping I expect to see same image, which i pick earlier.

Actual Behavior

Now after pressing Done image has some black extra view below. Also image lifts up by black view height.

Steps to Reproduce

I have this effect on each image, which i have picked without cropping. But if I do a little crop, black view goes, but lifts up continue.
screen shot 2016-04-18 at 12 44 00
image

clampButtonHidden no longer hides clamp button

toCropViewController.toolbar.clampButtonHidden = true

No longer works!
I have created a pull request which fixes it and I have refactored the new Clockwise code so it matches the rest of the code.

Square AspectRatio Issue

Hi Tim!

I'm glad to find this crop lib useful for me, I learn lot's from it and thank you.

While using it, I find two bugs.
I choose the Square AspectRatio after I choose a Pic, then I do nothing just rotate. If the pic is Not a square pic, when the pic rotate to vertical, the 'Square' grid overlay changed to the 'Original' shape again.

The second is also the 'Square' AspectRatio, I choose a vertical pic, Square AspectRatio, then I move the pic to end of the vertical pic, and then rotate, when the pic rotate to a horizontal direction, the foreground Image looks wrong.

Thanks!
ios simulator screen shot 2015 7 7 4 03 13

Weird header bar appears at the top, causing misalign between image and crop border

I'm getting a weird header bar that appears at the top of the view controller when using this library. It appears both in simulator (iphone 4,5,6 regardless) as well as real device (tested on iPhone 6 plus).

Here's the screenshot of portrait view that causes image and crop border to be not aligned:
ios simulator screen shot 12 sep 2015 13 56 51

And here's a screenshot of landscape view that causes the 'Done' button to be blocked:
ios simulator screen shot 12 sep 2015 13 57 37

Anyone facing the same issue?

Meanwhile I will try to debug this on my side as well.

Swift Implementation: Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan nan]'

Hi tim!!! I has import this Objective-C librari into a Swift project, with a bridge header, but when i try to do a presentViewController it trow me this error:


ERROR:

2016-03-20 21:59:30.214 ImageTest6[20286:2042246] *** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan nan]'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010cc97e65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010c710deb objc_exception_throw + 48
    2   CoreFoundation                      0x000000010cc97d9d +[NSException raise:format:] + 205
    3   QuartzCore                          0x0000000111e8ca86 _ZN2CA5Layer12set_positionERKNS_4Vec2IdEEb + 152
    4   QuartzCore                          0x0000000111e8cbf9 -[CALayer setPosition:] + 44
    5   QuartzCore                          0x0000000111e8d25d -[CALayer setFrame:] + 650
    6   UIKit                               0x000000010d30b25f -[UIView(Geometry) setFrame:] + 356
    7   ImageTest6                          0x000000010c1d1b3e -[TOCropView setCropBoxFrame:] + 1518
    8   ImageTest6                          0x000000010c1cd0a8 -[TOCropView layoutInitialImage] + 1432
    9   ImageTest6                          0x000000010c1ccb09 -[TOCropView didMoveToSuperview] + 73
    10  UIKit                               0x000000010d31221d __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 590
    11  UIKit                               0x000000010d311f69 -[UIView(Hierarchy) _postMovedFromSuperview:] + 544
    12  UIKit                               0x000000010d31fd8f -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1967
    13  ImageTest6                          0x000000010c1dd50e -[TOCropViewController viewDidLoad] + 830
    14  UIKit                               0x000000010d402f98 -[UIViewController loadViewIfRequired] + 1198
    15  UIKit                               0x000000010d4032e7 -[UIViewController view] + 27
    16  UIKit                               0x000000010dbadf87 -[_UIFullscreenPresentationController _setPresentedViewController:] + 87
    17  UIKit                               0x000000010d3d2f62 -[UIPresentationController initWithPresentedViewController:presentingViewController:] + 133
    18  UIKit                               0x000000010d415c8c -[UIViewController _presentViewController:withAnimationController:completion:] + 4002
    19  UIKit                               0x000000010d418f2c -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 489
    20  UIKit                               0x000000010d418a3b -[UIViewController presentViewController:animated:completion:] + 179
    21  ImageTest6                          0x000000010c1e703a _TFC10ImageTest614ViewController11viewDidLoadfS0_FT_T_ + 794
    22  ImageTest6                          0x000000010c1e71c2 _TToFC10ImageTest614ViewController11viewDidLoadfS0_FT_T_ + 34
    23  UIKit                               0x000000010d402f98 -[UIViewController loadViewIfRequired] + 1198
    24  UIKit                               0x000000010d4032e7 -[UIViewController view] + 27
    25  UIKit                               0x000000010d2d9ab0 -[UIWindow addRootViewControllerViewIfPossible] + 61
    26  UIKit                               0x000000010d2da199 -[UIWindow _setHidden:forced:] + 282
    27  UIKit                               0x000000010d2ebc2e -[UIWindow makeKeyAndVisible] + 42
    28  UIKit                               0x000000010d264663 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4131
    29  UIKit                               0x000000010d26acc6 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1760
    30  UIKit                               0x000000010d267e7b -[UIApplication workspaceDidEndTransaction:] + 188
    31  FrontBoardServices                  0x0000000110f09754 -[FBSSerialQueue _performNext] + 192
    32  FrontBoardServices                  0x0000000110f09ac2 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
    33  CoreFoundation                      0x000000010cbc3a31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    34  CoreFoundation                      0x000000010cbb995c __CFRunLoopDoSources0 + 556
    35  CoreFoundation                      0x000000010cbb8e13 __CFRunLoopRun + 867
    36  CoreFoundation                      0x000000010cbb8828 CFRunLoopRunSpecific + 488
    37  UIKit                               0x000000010d2677cd -[UIApplication _run] + 402
    38  UIKit                               0x000000010d26c610 UIApplicationMain + 171
    39  ImageTest6                          0x000000010c1e81fd main + 109
    40  libdyld.dylib                       0x000000010fba792d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

THE CODE I USE:

class ViewController: UIViewController,TOCropViewControllerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()

        var image:UIImage = UIImage()
        var cropViewController = TOCropViewController(image: image)
        cropViewController.delegate = self
        self.presentViewController(cropViewController, animated: true, completion: nil)
    }

    func cropViewController(cropViewController: TOCropViewController!, didCropToImage image: UIImage!, withRect cropRect: CGRect, angle: Int) {
        print("FINAL")
    }

}

Do you have any idea how i can do it to get it working??
It is a wonderfoul library but i am having problems importing in swift...

THANK YOU VERY MUCH !!!!

Cannot use delegate function in swift

I've successfully been able to import the library into my swift project, however despite adding the import statement as well as the delegate, I am still not able to add a swift version of " - (void)cropViewController:(TOCropViewController *)cropViewController didCropImageToRect:(CGRect)cropRect angle:(NSInteger)angle; " any idea why?

How to free rotate image

It wuold be nice a free rotation, with UIRotationGestureRecognizer or with a bar(like native iOS photo edit) thet enable image rotation for all degrees. The rotation must rotate only the image inside the canvas and the crop area must be fixed, so if i rotate an image for 45° and then take the crop i get back the cropped area back to his original size(like 3:4) with the rotated image inside. Is this possible? Any suggestion?

When presenting from popover view controller on iPad

This bug with transition occurs, when i present this beautiful view controller from popover view controller on my iPad.

For some reasons "presenting view controller" (my popover) gets frame from "presented view controller" (my cropViewController) during transition.

Now i forked your control and simply removed that line of code:
previousController.view.frame = containerView.bounds;
In file TOCropViewControllerTransitioning.m

I'm Waiting for update.

Thank you!

Watch video:
https://youtu.be/-d6oGx6KwWE

Forcing locked aspect ratio doesn't hide clamp button

Hi.

Setting 'lockedAspectRatio' to true does not hide the clamp button. Nor does setting 'toolbar.clampButtonHidden' to true hide it.

Is that a bug or expected behaviour?

Version 1.2.1 from CocoaPods, using in a Swift project.

Once reset cropped image, Unable to crop it again.

Hardware

Expected Behavior

On selecting an image for cropping, if we reset it to original image & again tries to crop it, image should be cropped.

Actual Behavior

If I reset the image to original state & tries to crop it again, image cannot be cropped.

Steps to Reproduce

  1. Select an image & open it in Crop View.
  2. Crop the image.
  3. Reset it to original state.
  4. Try to crop it again.
  5. Image will not be cropped.

setting the default image size

Can you help me to do the following..
after selecting an image if the done button is pressed without editing the photo, then the image should change to its default size/frame as 16:9 and it should be displayed on the first view controller....

Please help me to do it as soon as possible

Cropping With A Certain Rect At Start

Hi,

I've been modifying TOCropViewController so I can initialize it with a custom rect and am having some trouble doing that. I modified all the initializers and everything to accept the CGRect but I have no clue where to set it. I'm sure that this needs to happen in TOCropView, but am unsure. I've tried setting some instance variables in TOCropView and also calling setCropBoxFrame after initialization to no avail. Any ideas?

Thanks,
Ahan

Lock aspect ration but allow user to flip between landscape and portrait

Hey! Awesome view controller! It's exactly what I'm after so thank you.

I have a question - I want my users to be able to crop their photos at a locked aspect ration of 4:3. HOWEVER, they should be able to take any size of photo and choose to either crop it at 4:3 or 3:4.

i.e. the photo maybe a landscape photo, but they want to crop out a portrait-shaped section with aspect ration 3:4. Equally, they may want to crop out a landscape-shaped section with aspect ration 4:3.

Does your library allow this? Or you have any code which might let me do this?

Thanks so much!

Free angle rotation

Do you plan to add free angle rotation support similar to embedded gallery app?

how to make circular crop area?

I'd like to customize this package to provide a circular overlay rather than a square one. The output result image doesn't necessarily need to produce a circular image--I just need to display to the end user that it's a circle. I plan to take the resulting square and turn it into a circle later on display, but for user experience purposes, they should feel like they are cropping a circle.

hi sir how to set content size crop ?

self.presentViewController(cropController, animated: true, completion: nil)
cropController.cropView.setAspectLockEnabledWithAspectRatio(CGSizeMake(4, 1), animated: true)

it error...

Aspect Ratio not applying properly

Hello Tim,
I've found one issue with applying aspect ratio and I'd like to bring it to your attention. Please try cropping a picture with width of 130px and height of 490px. If I choose a fixed aspect ratio (4:5 for an example) from the menu, It's not applying properly first time. I have to do twice to get it right. Please fix this issue as soon as you can. Thank you in advance!

rotateClockwiseButtonHidden does not appear to work

Hardware

Simulator iOS 9.0

Expected Behavior

Something (a new button appearing)

Actual Behavior

Nothing

Steps to Reproduce

The toolbar does not change regardless if rotateClockwiseButtonHidden is set to YES or NO. I have tried setting it before presenting the view controller and in the completion handler. Same result - nothing happens.

image auto crop like ios question

Dear Tim Oliver:

 I am one image processer from china and doing image croping as ios, but how to detect the rotate angle for the auto crop, i do some experiments on this quesion,but can not to find a simple rule. I am Looking forward to your reply.

cropView.setAspectLockEnabledWithAspectRatio not working

Hi, I am developing an app using Swift 2.0 in which I need to take a photo and then crop a part with an aspect ration of 4:1 (a really wide image).
However I was unable to successfully build up the Crop controller and I am not really sure why is that.
No matter what I try I always get the same error output.

I would really appreciate if you can tell me how to set the default crop view to start at a ratio of 4:1.
Thanks :)

My code:

func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) {
        //Dismissing the imagePicker
        imagePicker.dismissViewControllerAnimated(false, completion: nil)

        //initializing the TOCropViewController 
        controller = TOCropViewController(image: image)
        controller.delegate = self
        controller.cropView.aspectRatioLocked = true
        controller.aspectRatioLocked = true
        animated: false)
        controller.rotateButtonsHidden = true
        controller.editing = true

        //Here is where I get the error
        controller.cropView.setAspectLockEnabledWithAspectRatio(CGSizeMake(4, 1), animated: false)
        presentViewController(controller, animated: false, completion: nil)    
    }

Console output:

*** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer bounds contains NaN: [nan nan; 375 667]' *** First throw call stack: (0x1823c1900 0x181a2ff80 0x1823c1848 0x184ab4b58 0x184ab49f8 0x187103da8 0x187112074 0x1870d22bc 0x1004ac448 0x1004ac0f8 0x1004ad040 0x1004ace40 0x100082214 0x1000827b0 0x187563570 0x18cb04fa8 0x18cb48cb8 0x18cb48b10 0x1870ebe50 0x1870ebdcc 0x1870d3a88 0x1870eb6e4 0x1870eb314 0x1870e3e30 0x1870b44cc 0x1870b2794 0x182378efc 0x182378990 0x182376690 0x1822a5680 0x1837b4088 0x18711cd90 0x10008568c 0x181e468b8) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.