Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 为什么不是';我的代码移动图像的位置?_Ios_Objective C - Fatal编程技术网

Ios 为什么不是';我的代码移动图像的位置?

Ios 为什么不是';我的代码移动图像的位置?,ios,objective-c,Ios,Objective C,我想要一个图像自动对齐到顶部,我想唯一想做的是通过制作一个框架来定位它。在做了一些研究之后,我似乎不明白为什么这个代码根本不移动图像。。。我在topPadding和leftPadding变量中替换了许多值 - (void)constructImageView:(UIImage *)image { CGFloat topPadding = 20.f; CGFloat leftPadding = 30.f; CGRect frame = CGRectMake(leftPadd

我想要一个图像自动对齐到顶部,我想唯一想做的是通过制作一个框架来定位它。在做了一些研究之后,我似乎不明白为什么这个代码根本不移动图像。。。我在topPadding和leftPadding变量中替换了许多值

- (void)constructImageView:(UIImage *)image {
    CGFloat topPadding = 20.f;
    CGFloat leftPadding = 30.f;
    CGRect frame = CGRectMake(leftPadding, topPadding, image.size.width, image.size.height);
    self.imageView = [[UIImageView alloc] initWithFrame:frame];
    self.imageView.image = image;
    [self addSubview:self.imageView];
}

你在使用自动布局吗?如果是,
setFrame
:无法与自动布局一起正常工作。如果是这样,那么您的选择是:

  • 使用此选项:
    self.view.translatesAutoresizingMaskIntoConstraints=YES
  • 编写自己的约束,而不是设置视图的框架

您是指self.imageView吗?它取决于您希望支持帧操作的视图