Я так смущен тем, как делать то, что мне нужно! Любая помощь очень ценится! У меня есть прозрачное изображение, на котором есть другое изображение, которое имеет UIPanGestureRecognizer и UIPinchGestureRecognizer, прикрепленные к нему. Верхнее изображение имеет полностью прозрачную середину, которая служит "стеклянным" видом. Я пытаюсь обрезать нижнее изображение на "стеклянную" часть, основанную на кастрюле и щепотке. (см. изображение ниже, чтобы увидеть, о чем я говорю) Я успешно позаботился об урожае панорамирования, но у меня проблемы с его обрезкой, когда применяется щепотка.
Я не использую snapshotViewAfterScreenUpdates.
Вот код, который у меня есть до сих пор:
UIImage *snapshotImage;
/* draw the image of all the views below our view */
UIGraphicsBeginImageContextWithOptions(self.pendantImageView.bounds.size, NO, 0);
BOOL successfulDrawHierarchy = [self.pendantImageView drawViewHierarchyInRect:self.pendantImageView.bounds afterScreenUpdates:YES];
if ( successfulDrawHierarchy ) {
snapshotImage = UIGraphicsGetImageFromCurrentImageContext();
} else {
NSLog(@"drawViewHierarchyInRect:afterScreenUpdates: failed - there nothing to draw...");
}
UIGraphicsEndImageContext();
UIImage *croppedImage;
if ( successfulDrawHierarchy ) {
/* calculate the coordinates of the rectangle we're interested in within the returned image */
CGRect cropRect = CGRectOffset(pendantFrame, - self.pendantImageView.frame.origin.x, - self.pendantImageView.frame.origin.y);
/* draw the cropped section with a clipping region */
UIGraphicsBeginImageContextWithOptions(cropRect.size, YES, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextClipToRect(context, CGRectMake(0, 0, cropRect.size.width, cropRect.size.height));
CGRect targetRectangeForCrop = CGRectMake(-cropRect.origin.x, -cropRect.origin.y, snapshotImage.size.width, snapshotImage.size.height);
[snapshotImage drawInRect:targetRectangeForCrop];
croppedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
pendantImageView - это нижнее изображениеView и pendantFrame - это средние координаты области, в которой я пытаюсь обрезать.
Спасибо заранее!