简体   繁体   中英

“setFrame” doesn't work for UIScrollView in iOS

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM