我使用名为 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/