sending UIScrollView to Background

2019-08-04 21:28发布

问题:

I'm midway of finishing my app. I noticed that one of my views needs extra vertical space so I need to add a UIScrollView. Yet when I add that scroll view it overlaps everything else in the view. In simple words if I need to get it to work properly I have to delete everything off the view , add the scroll view, and then re-add everything back! Is there anyway to send this scroll view to the background of the view? This is all the code that concerns the scroll view

@IBOutlet var scrollerForPOfFourBar: UIScrollView!

override func viewDidLoad() {
    super.viewDidLoad()
    /* non related code here*/

    scrollerForPOfFourBar.userInteractionEnabled = true
    scrollerForPOfFourBar.self.contentSize = CGSizeMake(320, 400)
}

回答1:

I'm assuming you're using Interface Builder since you marked your scrollView as an IBOutlet.

On the view list, on the left, the order of the views specifies their Z order, with the views at the bottom being the ones drawn on top (with the largest Z).

To move your scrollView to the back, drag it just underneath of the view, and drop it there.

Keep in mind that you will have to drag all the views you had in your view into the scrollView (the easiest is to do it in the views navigator as well), and you'll have to set up any Auto Layout constraints again, which will be a pain.



回答2:

Are you just want to move scrollerForPOfFourBar to back? Try this:

self.view.sendSubviewToBack(scrollerForPOfFourBar)


标签: swift xcode6