+ Landscape support in Attachment editor

This commit is contained in:
moritz haarmann
2014-05-05 12:12:22 +02:00
parent 4c88a10a8f
commit 1b4ea4492e
2 changed files with 22 additions and 8 deletions

View File

@@ -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];
}
}

View File

@@ -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;
}