UIViewContentModeScaleAspectFit在ios中的didFinishPickingMediaWithInfo中不起作用

时间:2015-11-19 09:51:31

标签: ios objective-c iphone xcode

我正在处理从图库中选择图像的应用程序。

我要从画廊中挑选的图片大小为50 * 50.

我正在使用UIViewContentModeScaleAspectFit将imageview设置为图像。虽然图像正如图像下方那样伸展。

enter image description here

以下是我的代码。

- (void)viewDidLoad
{
if (IS_IPHONE_6)
    {
        self.imgViewUserPic.frame=CGRectMake(10, 8, 300, 300);

    }
    else if (IS_IPHONE_6_Plus)
    {
        self.imgViewUserPic.frame=CGRectMake(10, 6, 320, 320);

    }
    else if (IS_IPHONE_4)
    {
        self.imgViewUserPic.frame=CGRectMake(50, 12, 220, 220);
    }
    else
    {
            self.imgViewUserPic.frame=CGRectMake(50, 12, 220, 220);
     }

}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{

    userImage = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

    NSLog(@"%f %f",userImage.size.width,userImage.size.height);
 // NSData *image_data = UIImageJPEGRepresentation(userImage, 0.8);

    self.imgViewUserPic.contentMode =  UIViewContentModeScaleAspectFit;

    self.imgViewUserPic.image=userImage;

    NSLog(@"%f %f",_imgViewUserPic.frame.size.width,_imgViewUserPic.frame.size.height);


    [picker dismissViewControllerAnimated:YES completion:nil];

}

请帮帮我。我只是在UIViewContentModeScaleAspectFit的帮助下将imageview调整为图片。

任何帮助都将不胜感激。

0 个答案:

没有答案