"setFrame "在iOS中对UIScrollView不起作用[英] "setFrame" doesn't work for UIScrollView in iOS

本文是小编为大家收集整理的关于"setFrame "在iOS中对UIScrollView不起作用的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我已经在情节板上放了一个卷轴.

接下来,在我调用的代码中

self.scroll.frame = CGRectMake(100, 0, 800, 900);

我想滚动应将位置更改为(100,0)

,但不知何故它仍然处于故事板中设置的原始位置.

我缺少什么?

推荐答案

是的

如果要在代码中设置框架初始化.

@property (nonatomic,strong) UIScrollView *scrollView;

_scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 568)];

如果要在Autolayout系统中设置位置,则应考虑更新视图的约束.

self.scrollViewWidthConstraint.constant += 20;
[self.scrollView updateConstraints]; 

本文地址:https://www.itbaoku.cn/post/2091185.html

问题描述

I've put a ScrollView in storyboard.

Next, in the code I call

self.scroll.frame = CGRectMake(100, 0, 800, 900);

I suppose the scroll should change the position into (100, 0)

But somehow it still remains in the original position where was set in storyboard.

What am I missing ?

推荐答案

Yes it won't work for any view in autolayout system at all if added using storyboard or xib.

If you want to set frame initialise in your code.

@property (nonatomic,strong) UIScrollView *scrollView;

_scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 568)];

If you want to set position in autolayout system you should consider updating the constraints of the view.

self.scrollViewWidthConstraint.constant += 20;
[self.scrollView updateConstraints];