2
即時通訊使用稱爲RSKImageCropView的小型庫,它有Delegate和DataSource方法。代表呼籲作爲expecterd,但數據源不。我的數據源方法從未因爲某種原因調用
這是我如何配置它:
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)
這裏是委託和數據源的方法:
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)
}
}