在 swift 中实施 Objective-C 框架 (TOCropViewController) 方法
Implementing Objective-C Framework (TOCropViewController) method in swift
我正在尝试实现一个用 CocoaPods (TOCropViewController) 编写的框架,并将其导入到 bridging-header 中,如下所示:
桥接Header
#import <TOCropViewController/TOCropViewController.h>
#import <TOCropViewController/TOCropView.h>
#import <TOCropViewController/TOCropToolbar.h>
#import <TOCropViewController/TOCropOverlayView.h>
我面临的问题是我不理解Objective-C,因此我不知道如何在Swift中实现这个框架。这是其页面上记录的基本实现:
- (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
}
我在 Swift 中尝试这样做:
self.presentCropViewController{
}
但不出所料,它给我一个错误,说 ViewController
的值没有成员 presentCropViewController
如有任何帮助,我们将不胜感激。
下面的代码可以帮助翻译,尽量理解Swift和Objective-C的关系,以后再做。
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) {
}
我正在尝试实现一个用 CocoaPods (TOCropViewController) 编写的框架,并将其导入到 bridging-header 中,如下所示:
桥接Header
#import <TOCropViewController/TOCropViewController.h>
#import <TOCropViewController/TOCropView.h>
#import <TOCropViewController/TOCropToolbar.h>
#import <TOCropViewController/TOCropOverlayView.h>
我面临的问题是我不理解Objective-C,因此我不知道如何在Swift中实现这个框架。这是其页面上记录的基本实现:
- (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
}
我在 Swift 中尝试这样做:
self.presentCropViewController{
}
但不出所料,它给我一个错误,说 ViewController
的值没有成员 presentCropViewController
如有任何帮助,我们将不胜感激。
下面的代码可以帮助翻译,尽量理解Swift和Objective-C的关系,以后再做。
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) {
}