我遇到了UIView的问题,它正在通过Camera Roll的图像进行摄取。
当我选择以纵向模式拍摄的照片时,视图总是将照片拉得太高,但是当我旋转设备时,照片拉伸得很好。
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { if(info){ { [artView removeFromSuperview]; artView = nil; artView = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]]; artView.image = [info objectForKey:UIImagePickerControllerOriginalImage]; artView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; artView.contentMode = UIViewContentModeScaleAspectFill; [self.contentView addSubview:artView];
感谢任何帮助。
答案 0 :(得分:5)
如果其他人仍然遇到此问题,请尝试在contentMode之后设置图片。
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
if (info) {
[artView removeFromSuperview];
artView = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
artView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
artView.contentMode = UIViewContentModeScaleAspectFill;
artView.image = [info objectForKey:UIImagePickerControllerOriginalImage];
[self.contentView addSubview:artView];
[artView release];
}
}
答案 1 :(得分:2)
你的代码看起来很好,除了它泄漏并且你有太多的开口括号和没有关闭括号。
您可能希望它看起来像这样:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
if (info) {
[artView removeFromSuperview];
artView = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
artView.image = [info objectForKey:UIImagePickerControllerOriginalImage];
artView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
artView.contentMode = UIViewContentModeScaleAspectFill;
[self.contentView addSubview:artView];
[artView release];
}
}
UIViewContentModeScaleAspectFill
不应该拉伸图像。它应该剪辑它。也许UIViewContentModeScaleAspectFit
正是你要找的?