【问题标题】:Implementing Objective-C Framework (TOCropViewController) method in swift快速实现 Objective-C 框架(TOCropViewController)方法
【发布时间】:2017-02-02 13:57:34
【问题描述】:

我正在尝试实现一个用 CocoaPods (TOCropViewController) 编写的框架,并将其导入到 bridging-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

任何帮助将不胜感激。

【问题讨论】:

    标签: ios objective-c swift bridging-header


    【解决方案1】:

    以下代码将帮助翻译,尝试理解 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) {
    
    }
    

    更多信息在这里https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html

    【讨论】:

    • 成功了 :) ,该链接将来一定会帮助我做到这一点,谢谢!
    猜你喜欢
    • 1970-01-01
    • 2014-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多