mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 22:55:00 +00:00
+ Landscape support in Attachment editor
This commit is contained in:
@@ -198,15 +198,11 @@
|
||||
for (BITFeedbackMessageAttachment *attachment in attachments){
|
||||
UIButton *imageView = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
[imageView setImage:[attachment thumbnailWithSize:CGSizeMake(ATTACHMENT_SIZE, ATTACHMENT_SIZE)] forState:UIControlStateNormal];
|
||||
[imageView setTitle:attachment.originalFilename forState:UIControlStateNormal];
|
||||
[imageView setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
|
||||
[imageView setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
|
||||
|
||||
[imageView addTarget:self action:@selector(imageButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
|
||||
|
||||
imageView.contentMode = UIViewContentModeScaleAspectFill;
|
||||
|
||||
[self.attachmentViews addObject:imageView];
|
||||
[self addSubview:imageView];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -103,24 +103,42 @@ typedef NS_ENUM(NSInteger, BITImageAnnotationViewControllerInteractionMode) {
|
||||
|
||||
- (void)viewWillAppear:(BOOL)animated {
|
||||
[super viewWillAppear:animated];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil];
|
||||
|
||||
[self fitImageViewFrame];
|
||||
|
||||
}
|
||||
|
||||
- (void)viewWillDisappear:(BOOL)animated {
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
|
||||
|
||||
}
|
||||
|
||||
- (BOOL)prefersStatusBarHidden {
|
||||
return self.navigationController.navigationBarHidden || self.navigationController.navigationBar.alpha == 0.0f;
|
||||
}
|
||||
|
||||
- (void)orientationDidChange:(NSNotification *)notification {
|
||||
[self fitImageViewFrame];
|
||||
}
|
||||
|
||||
|
||||
- (void)fitImageViewFrame {
|
||||
CGFloat heightScaleFactor = [[UIScreen mainScreen] bounds].size.height / self.image.size.height;
|
||||
CGFloat widthScaleFactor = [[UIScreen mainScreen] bounds].size.width / self.image.size.width;
|
||||
|
||||
CGSize size = [UIScreen mainScreen].bounds.size;
|
||||
if (UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)){
|
||||
size = CGSizeMake(size.height, size.width);
|
||||
}
|
||||
|
||||
CGFloat heightScaleFactor = size.height / self.image.size.height;
|
||||
CGFloat widthScaleFactor = size.width / self.image.size.width;
|
||||
|
||||
CGFloat factor = MIN(heightScaleFactor, widthScaleFactor);
|
||||
self.scaleFactor = factor;
|
||||
CGSize scaledImageSize = CGSizeMake(self.image.size.width * factor, self.image.size.height * factor);
|
||||
|
||||
CGRect baseFrame = CGRectMake(self.view.frame.size.width/2 - scaledImageSize.width/2, self.view.frame.size.height - [[UIScreen mainScreen] bounds].size.height, scaledImageSize.width, scaledImageSize.height);
|
||||
CGRect baseFrame = CGRectMake(self.view.frame.size.width/2 - scaledImageSize.width/2, self.view.frame.size.height - size.height, scaledImageSize.width, scaledImageSize.height);
|
||||
|
||||
self.imageView.frame = baseFrame;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user