“setFrame” doesn't work for UIScrollView in iOS

大兔子大兔子 提交于 2019-12-12 00:31:36

问题


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 ?


回答1:


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]; 


来源:https://stackoverflow.com/questions/32198375/setframe-doesnt-work-for-uiscrollview-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!