【发布时间】:2014-12-30 09:53:50
【问题描述】:
我正在尝试使用 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];
}
imageView 在 NSLog 中的输出是:
<UIImageView: 0x18f695b0; frame = (0 0; 640 640); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x18f14240>>
框架对于我设置为 (60 227; 200 200) 的实际 UIImageView 来说太大了
我认为这就是为什么我在运行我的应用程序时根本看不到 UIImageView 的原因。我该如何解决这个问题?
编辑:
在 PAWWallPostCreateViewController.h 中
@property (nonatomic, strong) IBOutlet UIImageView *imageView;
我将 imageView 链接到我的 .xib 文件
还有谁熟悉 autoresize = RM+BM;因为通常当我使用 imagePickerController 将 UIImage 放在同一视图控制器的 UIImageView 中时,我的 UIImageView 数据具有 autoresize = RM+BM;属性 所以我想要的代码通常看起来像
<UIImageView: 0x1a2b4b30; frame = (60 227; 200 200); opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x1a2b4bb0>>
但这就是我在这种情况下得到的结果
【问题讨论】:
-
试试 imageView.contentMode = UIViewContentModeScaleAspectFit;
-
什么都不做。我更新了代码以显示我做了什么
-
你能展示一下你是如何在 PAWWallPostCreateViewController 中添加 imageview 的吗?
-
我编辑了上面的代码。我刚刚定义了@property (nonatomic, strong) IBOutlet UIImageView *imageView;在我的 .h 文件中并将其链接到我的 .xib 文件
标签: ios objective-c uiviewcontroller uiimageview frame