mirror of
https://github.com/GLEGram/GLEGram-iOS.git
synced 2026-04-29 14:36:31 +02:00
4647310322
Based on Swiftgram 12.5 (Telegram iOS 12.5). All GLEGram features ported and organized in GLEGram/ folder. Features: Ghost Mode, Saved Deleted Messages, Content Protection Bypass, Font Replacement, Fake Profile, Chat Export, Plugin System, and more. See CHANGELOG_12.5.md for full details.
64 lines
2.5 KiB
Objective-C
64 lines
2.5 KiB
Objective-C
#import "TGAttachmentPhotoCell.h"
|
|
#import <LegacyComponents/TGModernGalleryTransitionView.h>
|
|
|
|
NSString *const TGAttachmentPhotoCellIdentifier = @"AttachmentPhotoCell";
|
|
|
|
@interface TGAttachmentPhotoCell () <TGModernGalleryTransitionView>
|
|
|
|
@end
|
|
|
|
@implementation TGAttachmentPhotoCell
|
|
|
|
- (UIImage *)transitionImage
|
|
{
|
|
CGFloat scale = 1.0f;
|
|
CGSize scaledBoundsSize = CGSizeZero;
|
|
CGSize scaledImageSize = CGSizeZero;
|
|
|
|
if (self.imageView.image.size.width > self.imageView.image.size.height)
|
|
{
|
|
scale = self.frame.size.height / self.imageView.image.size.height;
|
|
scaledBoundsSize = CGSizeMake(self.frame.size.width / scale, self.imageView.image.size.height);
|
|
|
|
scaledImageSize = CGSizeMake(self.imageView.image.size.width * scale, self.imageView.image.size.height * scale);
|
|
|
|
if (scaledImageSize.width < self.frame.size.width)
|
|
{
|
|
scale = self.frame.size.width / self.imageView.image.size.width;
|
|
scaledBoundsSize = CGSizeMake(self.imageView.image.size.width, self.frame.size.height / scale);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
scale = self.frame.size.width / self.imageView.image.size.width;
|
|
scaledBoundsSize = CGSizeMake(self.imageView.image.size.width, self.frame.size.height / scale);
|
|
|
|
scaledImageSize = CGSizeMake(self.imageView.image.size.width * scale, self.imageView.image.size.height * scale);
|
|
|
|
if (scaledImageSize.width < self.frame.size.width)
|
|
{
|
|
scale = self.frame.size.height / self.imageView.image.size.height;
|
|
scaledBoundsSize = CGSizeMake(self.frame.size.width / scale, self.imageView.image.size.height);
|
|
}
|
|
}
|
|
|
|
CGRect rect = self.bounds;
|
|
UIGraphicsBeginImageContextWithOptions(rect.size, false, 0.0f);
|
|
|
|
CGContextRef context = UIGraphicsGetCurrentContext();
|
|
[[UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height) cornerRadius:TGAttachmentMenuCellCornerRadius] addClip];
|
|
|
|
CGContextScaleCTM(context, scale, scale);
|
|
[self.imageView.image drawInRect:CGRectMake((scaledBoundsSize.width - self.imageView.image.size.width) / 2,
|
|
(scaledBoundsSize.height - self.imageView.image.size.height) / 2,
|
|
self.imageView.image.size.width,
|
|
self.imageView.image.size.height)];
|
|
|
|
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
|
|
UIGraphicsEndImageContext();
|
|
|
|
return image;
|
|
}
|
|
|
|
@end
|