Діма Комар
Діма Комар

Reputation: 552

my DataSource Method never called for some reason

im using small library called RSKImageCropView and it got Delegate and DataSource methods. The Delegate called as expecterd but the DataSource dont.

here is how i configure it:

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)

here is Delegate and DataSource methods:

    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)
    }
}

Upvotes: 2

Views: 258

Answers (1)

Aaron Randall
Aaron Randall

Reputation: 11

I believe you need to set the controller's cropMode to Custom for methods like imageCropViewControllerCustomMaskPath to be called, so try changing your instantiation to something like:

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

Upvotes: 1

Related Questions