0

I have a scene where I just want the scroll to be vertical not horizontal. I have tried to program it to disable but that doesn't seem to work. I also run into the issue where it isn't auto resizing to different phone screens. Im kinda new at this and I'm just really stuck. Any help?

Disable Code:

@IBOutlet var scrollview: UIScrollView!

override func viewDidLoad() {
    super.viewDidLoad()

    scrollview.contentSize.height = 800
    scrollview.contentSize.width = 0

Screenshot

  • Did you try this? http://stackoverflow.com/questions/1062693/how-to-disable-horizontal-scrolling-of-uiscrollview – hannad Dec 16 '15 at 12:19

3 Answers3

3

I think problem is with this line

scrollview.contentSize.width=0

Try to set width equal to screen width like this,

scrollview.contentSize.width=[UIScreen mainScreen].bounds.size.width;

Scrollview will scroll horizontally when it's contentSize.width is greater than viewcontroller's width.

Hope it will solve the issue.

bisma
  • 795
  • 6
  • 26
1

I think you are not applying constraints on UIScrollView properly now first of all you have to properly add constraint on scrollview and no need to set contentsize from code.

http://spin.atomicobject.com/2014/03/05/uiscrollview-autolayout-ios/

Hope this tutorial will help you better understand the ScrollView

Muhammad Waqas Bhati
  • 2,775
  • 20
  • 25
0
var scrollView: UIScrollView!

override func viewDidLoad() {
    super.viewDidLoad()
    self.scrollView = UIScrollView()
    self.scrollView.contentSize = CGSizeMake(1000, 1000)
    self.view.addSubview(scrollView)
}
T.Grosche
  • 16
  • 3