1
我遵循教程:https://www.youtube.com/watch?v=1_daE3IL_1s,教您如何在swift 3中創建快速聊天菜單,其中每次您在屏幕上刷新子視圖時,但它是唯一的一個,你需要滑動另一次來獲得下一個視圖。本教程是在swift 2中完成的,但是當我更新到swift 3時,scrollview現在就像普通的滾動視圖一樣流暢地滾動。有沒有什麼辦法解決這一問題?主視圖控制器如何使UIScrollview一次只顯示一個子視圖
代碼:
class ViewController: UIViewController {
@IBOutlet weak var scrollView: UIScrollView!
override func viewDidLoad() {
super.viewDidLoad()
let V1: View1 = View1(nibName: "View1", bundle: nil)
let V2: View2 = View2(nibName: "View2", bundle: nil)
let V3: View3 = View3(nibName: "View3", bundle: nil)
V1.didMove(toParentViewController: self)
self.addChildViewController(V1)
self.scrollView.addSubview(V1.view)
V2.didMove(toParentViewController: self)
self.addChildViewController(V2)
self.scrollView.addSubview(V2.view)
V3.didMove(toParentViewController: self)
self.addChildViewController(V3)
self.scrollView.addSubview(V3.view)
var V2Frame: CGRect = V2.view.frame
V2Frame.origin.x = self.view.frame.width
V2.view.frame = V2Frame
var V3Frame: CGRect = V3.view.frame
V3Frame.origin.x = 2 * self.view.frame.width
V3.view.frame = V3Frame
self.scrollView.contentSize = CGSize(width: self.view.frame.width*3 , height: self.view.frame.size.height)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
這是新的SWIFT 3? (謝謝btw) –
編號iOS2 +:https://developer.apple.com/reference/uikit/uiscrollview/1619432-pagingenabled?language=objc – shallowThought