简体   繁体   中英

How to change the position and size of a UIScrollView?

I got frustrated with AutoLayout so I decided to disable it and just set the positions and sizes of the elements in my view programatically. I tried this:

func setScrollViewBounds() {
    var windowFrame = self.view.frame;

    var scrollerHeigth = (windowFrame.height/100)*15

    BottomScroll.frame = CGRect(x: CGFloat(10), y: windowFrame.height-scrollerHeigth, width: windowFrame.width-20, height: scrollerHeigth);
    TopScroll.frame = CGRect(x: CGFloat(10), y: BottomScroll.frame.maxY-10, width: windowFrame.width-20, height: scrollerHeigth)
}

Im trying to set the two scroll views ( TopScroll and BottomScroll ) to be at the bottom of the page and have one be on top of the other. This however doesn't seem to do anything. Any ideas why?

I'm calling the function in ViewDidLoad() . TopScroll and BottomScroll are IBOutlets.

Apply constraint following order

Put your subviews in UIView Object(Which will subview of ScrollView).

Select Both ScrollView and UIView

Go->Pin->Equal Width.(Not Equal Height)

Select UIScrollView Go-> Pin uncheck Constraint to Margin and give Top,Bottom,Left,Right constraint.

Now Select UIView(Subview of UIScrollview say contentView) control click contentView to Main View(Default controller's View) and select Leading,Trailing,Top,Bottom constraint.

Finally Select contentView Go-> Resolve Auto-layOut issue -> Reset to Suggested constraints.

Constraints for subview of ContentView as usual with respect to contentView. use viewDidLayoutSubview for setting content-size to UIScrollView.

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