Closed LaChrome closed 7 years ago
Here is a quick hack / fix to get the portrait image to work (resize with aspect fit):
CGRect scaledImageRect = CGRectZero;
CGSize newSize = CGSizeMake(300, 300);
CGFloat aspectWidth = newSize.width / previewImage.size.width;
CGFloat aspectHeight = newSize.height / previewImage.size.height;
CGFloat aspectRatio = MIN ( aspectWidth, aspectHeight );
scaledImageRect.size.width = previewImage.size.width * aspectRatio;
scaledImageRect.size.height = previewImage.size.height * aspectRatio;
scaledImageRect.origin.x = (newSize.width - scaledImageRect.size.width) / 2.0f;
scaledImageRect.origin.y = (newSize.height - scaledImageRect.size.height) / 2.0f;
UIGraphicsBeginImageContextWithOptions( newSize, NO, 0 );
[previewImage drawInRect:scaledImageRect];
UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Portrait images are indeed a problem when displayed in a dialog. This is also true for large amounts of text, even more so on smaller devices like the iPhone 4S and landscape orientation. Therefore, it is your responsibility to make sure the dialog does not exceed the viewport in any of those cases, as the standard PopupDialog does not know about your intentions.
Having said that, if you need a custom solution like scroll views to handle these situations, you can always use a custom view controller with PopupDialog.
Report
Environment
Please provide information on your development environment, so we can build with the same scenario.
Dependency management
If you are not using any dependency managers, you can remove this section.
What did you do?
Initialized PopupDialog with a portrait UIImage (see code at very bottom of this report)
What did you expect to happen?
Expected image / Popup to scale proportionally so that all buttons show and popup fits in view.
What happened instead?
Popup goes out of view, and doesn't show bottom cancel button (below photo button). See attached screenshot. I've used multiple portrait photos, and this issue happens for each photo used.
Project that demonstrates the issue
Code: NSString previewPath = [[NSHomeDirectory() stringByAppendingString:self.currentProject.directoryName] stringByAppendingPathComponent:@"preview.png"]; CGDataProviderRef imgDataProvider = CGDataProviderCreateWithCFData((CFDataRef)[NSData dataWithContentsOfFile:previewPath]); CGImageRef image = CGImageCreateWithPNGDataProvider(imgDataProvider, NULL, true, kCGRenderingIntentDefault); UIImage previewImage = [[UIImage alloc] initWithCGImage:image];