Objective c 有人知道我怎样才能得到“你知道吗?”;“真正的”;UIImageView的大小,而不是创建框架

Objective c 有人知道我怎样才能得到“你知道吗?”;“真正的”;UIImageView的大小,而不是创建框架,objective-c,uiimageview,Objective C,Uiimageview,我希望有某种功能可以拍摄我照片的真实尺寸 CGRect myImageRect = CGRectMake(0.0f, 0.0f, 320.0, 210.0f); // 234 UIImageView *myImage = [[UIImageView alloc] initWithFrame:myImageRect]; [myImage setImage:[UIImage imageNamed:@"start.png"]]; 使用CGRectM

我希望有某种功能可以拍摄我照片的真实尺寸

CGRect myImageRect = CGRectMake(0.0f, 0.0f, 320.0, 210.0f);  // 234
            UIImageView *myImage = [[UIImageView alloc] initWithFrame:myImageRect];

            [myImage setImage:[UIImage imageNamed:@"start.png"]];
使用CGRectMake,它可以做这样的事情….(imageViewHeight

CGFloat imageViewHeight=[myImage frame].size.height


这样我就可以得到真实的尺寸,而不必像你上面看到的那样定义它。

我真的不明白你的要求,但这里有一个镜头:

如果您有一个UIImage,并且您想知道它的大小,您可以要求它提供它的
-[UIImage size]
属性

但是,如果要创建与UIImage大小相同的UIImageView,则只需使用
-[UIImageView initWithImage:]
,它将自动设置UIImageView的框架以对应于图像的尺寸


但是,如果您只是想更改当前现有视图的尺寸,那么在不干扰视图的
帧的情况下,很难做到这一点。您可以应用仿射变换对其进行缩放,但更容易操作帧。

看起来您要求将图像添加到imagev在不首先创建框架的情况下查看。如果是这种情况,可以执行以下操作:

UIImageView *myImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"start.png"]];

据我所知,您正在查找UIImageView对象中使用的图像的大小。为此,UIImageView中没有内置函数,但您可以通过以下方式执行此操作:

NSString* image= [myImage image].accessibilityIdentifier; // Get the image's name
UIImage *img = [UIImage imageNamed:image]; // Create an image object with that name
CGSize size = img.size; // Get the size of image
希望这对你的问题有所帮助