简体   繁体   中英

Xcode 8 & Swift 3 - Scroll View and .Xib Files not working

So I followed a tutorial online to make snapchat like menu. I used this tutorial to make a entire app. Since upgrading to Xcode 8 and swift 3 , I can no longer get the .Xib file to load.

I have a scroll view, with a .xib file being loaded onto that. using this code

@IBOutlet var scrollView: UIScrollView!

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    var V1 : View1 = View1(nibName: "View1", bundle: nil)


    self.addChildViewController(V1)
    self.scrollView.addSubview(V1.view)
    V1.didMove(toParentViewController: self)
}

This use to work but when I build and run nothing happens, this is what the screen is meant to look like .Xib inside Xcode

But this is what it runs like

While running in the simulator

Any help would be greatly thanked.

你这样做是错的。

var V1 = Bundle.main.loadNibNamed("View1", owner: self, options: nil)?[0] as! View1

I have observed this issue while migrating to xCode 8 with scroll views.

To resolve this issue add a view eg content view inside the scroll view in the storyboard. The frame of the content view should be exactly equal to scroll view with with all edges aligning to scroll view, with fixed height and fixed width. You can change scroll view contentSize later programatically.

Add the the view from the xib file as a subview to the content view.

在此处输入图片说明

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