我正在使用BWWalkthrough库进行个人演练。它实现起来非常简单但我在BWWalkthroughViewController上有一个错误:我不会使用storyboard来创建这个主控制器,所以我通过代码创建了我的自定义视图,然后在BWWalkthroughViewController的viewDidLoad中设置了视图和pageControl。其余代码与github存储库中的示例相同。
这是BWWalkthroughViewController的viewDidLoad:
override func viewDidLoad() {
super.viewDidLoad()
let welcomeview: WelcomeView = WelcomeView() // my custom view
view = welcomeview
self.pageControl = welcomeview.pageControl
...
}
并且,因为它是第一个视图,所以rootViewController使用BWWalkthroughViewController设置并修改了viewDidLoad。所以我有一个函数用于在AppDelegate.swift中设置这个演练:
func showWelcomeView() -> BWWalkthroughViewController{
let storyboard = UIStoryboard(name: "Welcome", bundle: nil)
let walkthrough: BWWalkthroughViewController = BWWalkthroughViewController()
let page_zero = storyboard.instantiateViewControllerWithIdentifier("walk_0") as! UIViewController
let page_one = storyboard.instantiateViewControllerWithIdentifier("walk_1") as! UIViewController
let page_two = storyboard.instantiateViewControllerWithIdentifier("walk_2") as! UIViewController
let page_three = storyboard.instantiateViewControllerWithIdentifier("walk_3") as! UIViewController
let page_four = storyboard.instantiateViewControllerWithIdentifier("walk_4") as! UIViewController
walkthrough.delegate = self
walkthrough.addViewController(page_zero)
walkthrough.addViewController(page_one)
walkthrough.addViewController(page_two)
walkthrough.addViewController(page_three)
walkthrough.addViewController(page_four)
return walkthrough
}
我在这里使用那个功能:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
self.window?.rootViewController = showWelcomeView() // func usedhere
return true
}
该应用运行没有错误。我可以看到我的自定义视图和所有4个子视图(walk_0 ... walk_4),我可以滑动它们但没有正确:可滚动是免费的,并且不会在每个页面上停止。
所以...我错过了自定义视图的一些步骤?请帮帮我!
这是来自我的iPhone的截图,其中滚动位于2个子视图之间:
答案 0 :(得分:1)
我已经通过在BWWalkthroughViewController
中使用scrollview的属性来解决这个问题override func viewDidLoad() {
super.viewDidLoad()
..
scrollview.pagingEnabled = true
}
工作正常,但不知道为什么。该滚动视图的默认值为pagingeEnabled = true
在init中设置:
required init(coder aDecoder: NSCoder) {
// Setup the scrollview
scrollview = UIScrollView()
scrollview.showsHorizontalScrollIndicator = false
scrollview.showsVerticalScrollIndicator = false
scrollview.pagingEnabled = true // Default of scrollview
// Controllers as empty array
controllers = Array()
super.init(coder: aDecoder)
}
答案 1 :(得分:0)
你有没有连接
@IBOutlet var pageControl:UIPageControl?
和视图控制器中的页面控制器?