用相机拍摄的照片不会在uiimageview中调整大小

时间:2014-12-08 13:21:00

标签: ios objective-c uiimageview

我的代码

- (IBAction)takePhoto:(UIButton *)sender {
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
    UIImagePickerController *picker = [UIImagePickerController new];
    picker.delegate = self;
    picker.allowsEditing = YES;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;

    [self presentViewController:picker animated:YES completion:nil];
}else{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"ERROR!" message:@"Device has no camera!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
}
}

和代表

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.userImage.image = chosenImage;

[picker dismissViewControllerAnimated:YES completion:NULL];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {

[picker dismissViewControllerAnimated:YES completion:NULL];

}

嗯,这非常简单和基本。我的问题是,在将我的图像分配给UIImageView后(它具有固定/固定的宽度和高度)而不是将其自身调整为uiimageview的大小,它在整个视图中延伸,更像是放置图像的背景它应该在哪里。同样,我的uiimageview的宽度和高度已固定。有人可以帮忙吗?感谢

1 个答案:

答案 0 :(得分:0)

contentMode的{​​{1}}应为UIImageView,而不是UIViewContentModeScaleAspectFit

如果您需要动态更改内容模式,只需添加以下行:

UIViewContentModeCenter