[英]How to make UIImageView correct frame size?
I'm trying to take a picture using imagePickerController and show the image in a UIImageView in another ViewController. 我正在尝试使用imagePickerController拍摄图片,并在另一个ViewController的UIImageView中显示图像。
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissViewControllerAnimated:YES completion:NULL];
PAWWallPostCreateViewController *wallPostCreateViewController = [[PAWWallPostCreateViewController alloc] initWithNibName:@"PAWWallPostCreateViewController" bundle:nil];
wallPostCreateViewController.myImage = info[UIImagePickerControllerEditedImage];
wallPostCreateViewController.imageView = [[UIImageView alloc] initWithImage:wallPostCreateViewController.myImage];
wallPostCreateViewController.imageView.contentMode = UIViewContentModeScaleAspectFit;
NSLog(@"%@",wallPostCreateViewController.imageView); // Output below
[self.navigationController presentViewController:wallPostCreateViewController animated:YES completion:nil];
}
The output in NSLog for the imageView is: NSLog中imageView的输出为:
<UIImageView: 0x18f695b0; frame = (0 0; 640 640); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x18f14240>>
The frame is much too big for my actual UIImageView which is set to (60 227; 200 200) 对于我设置为(60227; 200200)的实际UIImageView而言,框架太大了
I think this is the reason why I can't see UIImageView at all when I run my app. 我认为这就是为什么我运行应用程序时根本看不到UIImageView的原因。 How do I fix this? 我该如何解决?
EDIT: 编辑:
In PAWWallPostCreateViewController.h 在PAWWallPostCreateViewController.h中
@property (nonatomic, strong) IBOutlet UIImageView *imageView;
I linked imageView to my .xib file 我将imageView链接到我的.xib文件
Also is anyone familiar with autoresize = RM+BM; 也有人熟悉autoresize = RM + BM; Because usually when I have used imagePickerController to put the UIImage in a UIImageView of the same view controller my UIImageView data has a autoresize = RM+BM; 因为通常当我使用imagePickerController将UIImage放在同一视图控制器的UIImageView中时,我的UIImageView数据具有autoresize = RM + BM; attribute so the code I want usually looks like 属性,所以我想要的代码通常看起来像
<UIImageView: 0x1a2b4b30; frame = (60 227; 200 200); opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x1a2b4bb0>>
But that's now what I'm getting in this case 但这就是我在这种情况下得到的
只需在ViewDidLoad()的第二个视图控制器下调用此行
self.imageView.contentMode = UIViewContentModeScaleAspectFit;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.