Reputation: 1553
I know there are tens of similar question about scrollview but I have tried everything, Scrollview
is not scrolling.
First I created a uiviewcontroller
with a xib file, and set it to freeform and arrange the size of it and added a scrollview on view.
Then added it as a childviewcontroller
to another view controller.
-(void)scrollViewSetup
{
if (!_scrollView) {
_scrollView=[[UIView alloc] initWithFrame:CGRectMake(0,200,self.scrollView.frame.size.width,200)];
[self.view addSubview:_scrollView];
ScrollView *displayPortf=[[ScrollView alloc] init];
//add as a child view controller here
//displayPortf.delegate=(id)self;
[_scrollView addSubview:displayPortf.view];
[displayPortf didMoveToParentViewController:self];
[self addChildViewController:displayPortf];
}
}
Content size of scroll view is (768,200)
on iPad.
I tried setting content size
to (1920,200)
in viewDidLoad
didn't work then viewDidAppear
didn't work then viewDidLayoutSubviews
didn't work.
Then I checked the use auto layout
box and tried to add constants by goingeditor->resolve auto layout issues->add constraints
How can I make scrollview to scroll?
Note: Parent view uses auto layout and storyboard.
Upvotes: 0
Views: 98
Reputation: 13312
I guess that the reason of issue is zero width of scrollView
.
When you call this:
_scrollView=[[UIView alloc] initWithFrame:CGRectMake(0,200,self.scrollView.frame.size.width,200)];
_scrollView
is initiated with width self.scrollView.frame.size.width
, but at this moment self.scrollView
is nil as it related to instance variable _scrollView
that hasn't initiated yet.
Try to set some non zero float value for view width:
_scrollView=[[UIView alloc] initWithFrame:CGRectMake(0,200,768,200)];
Upvotes: 1