ios - 我的 DataSource 方法由于某种原因从未调用过

标签 ios swift

我使用名为 RSKImageCropView 的小型库,它有 Delegate 和 DataSource 方法。 Delegate 被称为 expecterd 但 DataSource 没有。

我是这样配置的:

let someImage = UIImage(data: blob)

    let controller: RSKImageCropViewController = RSKImageCropViewController(image: someImage!, cropMode: RSKImageCropMode.Circle)
    controller.delegate = self
    controller.dataSource = self
    self.navigationController?.pushViewController(controller, animated: true)

这里是 Delegate 和 DataSource 方法:

    extension GameViewController:  RSKImageCropViewControllerDataSource {
    func imageCropViewControllerCustomMaskRect(controller: RSKImageCropViewController) -> CGRect {

        let rect = CGRect(x: 30, y: 30, width: 30, height: 30)
        return rect

    }

    func imageCropViewControllerCustomMovementRect(controller: RSKImageCropViewController) -> CGRect {
        return controller.maskRect
    }

    func imageCropViewControllerCustomMaskPath(controller: RSKImageCropViewController) -> UIBezierPath {
        let rect = controller.maskRect;
        let point1 = CGPointMake(CGRectGetMinX(rect), CGRectGetMaxY(rect));
        let point2 = CGPointMake(CGRectGetMaxX(rect), CGRectGetMaxY(rect));
        let point3 = CGPointMake(CGRectGetMidX(rect), CGRectGetMinY(rect));

        let triangle = UIBezierPath()
        triangle.moveToPoint(point1)
        triangle.addLineToPoint(point2)
        triangle.addLineToPoint(point3)
        triangle.closePath()
        print("yay")
        return triangle
    }
}

extension GameViewController: RSKImageCropViewControllerDelegate {
    func imageCropViewControllerDidCancelCrop(controller: RSKImageCropViewController) {
        self.navigationController?.popViewControllerAnimated(true)
    }

    func imageCropViewController(controller: RSKImageCropViewController, didCropImage croppedImage: UIImage, usingCropRect cropRect: CGRect, rotationAngle: CGFloat) {
        NSNotificationCenter.defaultCenter().postNotificationName("choseImage", object: croppedImage)
        self.navigationController?.popViewControllerAnimated(true)
    }
}

最佳答案

我相信您需要将 Controller 的 cropMode 设置为 Custom 才能调用 imageCropViewControllerCustomMaskPath 之类的方法,因此请尝试将实例化更改为某些内容喜欢:

let controller: RSKImageCropViewController = RSKImageCropViewController(image: someImage!, cropMode: RSKImageCropMode.Custom)

关于ios - 我的 DataSource 方法由于某种原因从未调用过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34421123/

相关文章:

ios - URLSession 完成处理程序应用程序崩溃

ios - UISearchControllerDelegate - 搜索栏在表头中不可见

ios - osx 上的 sem_open 共享内存在哪里

ios - 快速缩放 UIwebview

ios - 打开 Swift Playground 书

iOS:我应该始终为我的 map 创建自定义注释类吗?

javascript - swift WebView : How to call correctly swift code from javascript?

swift - 加载自定义 CollectionViewCell Nib 时 initWithCoder 错误

ios - React-Native NavigatorIOS 错误不适用于背景图像

ios - 在弹出时将数据传回 uiviewcontroller (NavigationController.PopViewController)