I am trying to implement a framework written in CocoaPods ( TOCropViewController ) and have imported it in the bridging-header like this:
Bridging Header
#import <TOCropViewController/TOCropViewController.h>
#import <TOCropViewController/TOCropView.h>
#import <TOCropViewController/TOCropToolbar.h>
#import <TOCropViewController/TOCropOverlayView.h>
The problem I am facing is that I don't understand Objective-C and therefore I don't know how to implement this framework in Swift. This is the basic implementation documented on it's page:
- (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
}
I tried to do this in Swift like this:
self.presentCropViewController{
}
But as expected, it gives me an error saying that the value of ViewController
has no member presentCropViewController
Any help would be appreciated.
The following code will help with the translation, try to understand the relationship between Swift and Objective-C so you can do this in the future.
func presentCropViewController() {
let image = ...
let cropViewController = TOCropViewController(image: image)
cropViewController.delegate = self
present(viewController: cropViewController, animated: true, completion: nil)
}
func cropViewController(_ cropViewController: TOCropViewController, didCropToImage image: UIImage, withRect cropRect: CGRect, angle angle: NSInteger) {
}
More info found here https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.