Я так запуталась, как делать то, что мне нужно! Любая помощь очень ценится! У меня есть наложение прозрачного изображения, за которым стоит другое изображение, к которому прикреплены 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's 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 - это нижний imageView, а pendantFrame - это средние координаты области, которую я пытаюсь обрезать.
Заранее спасибо!