简体   繁体   中英

Storyboard UIScrollView won't work

I created an UIScrollView inside a UIView and have put a couple labels and buttons in it.

The buttons and labels go on longer than the view frame, so I put this in the viewControllers viewDidLoad , like so:

-(void)viewDidLoad  {
    [[UIApplication sharedApplication] endIgnoringInteractionEvents];
    self.scrollView.contentSize = CGSizeMake(321, 600);
    self.scrollView.frame = self.view.frame;
}

I also set Bounce Vertically to true , so I can bounce the view lower, and it seems as if it's 'scrolling' but then as soon as I let go and it 'unbounces', it goes away.

Why won't my scroll view scroll and stay down?

How are you adding the labels and buttons? If you are using Storyboard and Auto Layout, you will need to set constraints.

Check my answer here on how to do it.

Are you using AutoLayout? If yes then this article will help you, follow it.

http://samwize.com/2014/03/14/how-to-use-uiscrollview-with-autolayout/

If not then try to set frame before setting the contentsize of ScrollView.

Other thing, if you are using AutoLayout with ScrollView then you would not be able to set frame anyway as Xcode does not allow it.

首先,您应该尝试添加以下行:

[self.scrollView setScrollEnabled: YES];

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