我的代码
- (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的宽度和高度已固定。有人可以帮忙吗?感谢
答案 0 :(得分:0)
contentMode
的{{1}}应为UIImageView
,而不是UIViewContentModeScaleAspectFit
。
如果您需要动态更改内容模式,只需添加以下行:
UIViewContentModeCenter