Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用不带故事板的穿行库,穿行自定义_Ios_Swift_Bwwalkthrough - Fatal编程技术网

Ios 使用不带故事板的穿行库,穿行自定义

Ios 使用不带故事板的穿行库,穿行自定义,ios,swift,bwwalkthrough,Ios,Swift,Bwwalkthrough,我正在使用图书馆进行个人演练。它的实现非常简单,但我在BWwalkthrowhViewController中有一个错误:我不会使用故事板来创建这个主控制器,所以我通过代码创建了我的自定义视图,然后在BWwalkthrowhViewController的viewDidLoad中设置了视图和页面控件。其余代码与github存储库中的示例相同 这是BWwalkthrowViewController的viewDidLoad: override func viewDidLoad() { super

我正在使用图书馆进行个人演练。它的实现非常简单,但我在BWwalkthrowhViewController中有一个错误:我不会使用故事板来创建这个主控制器,所以我通过代码创建了我的自定义视图,然后在BWwalkthrowhViewController的viewDidLoad中设置了视图和页面控件。其余代码与github存储库中的示例相同

这是BWwalkthrowViewController的viewDidLoad:

override func viewDidLoad() {
    super.viewDidLoad()
    let welcomeview: WelcomeView = WelcomeView() // my custom view
    view = welcomeview
    self.pageControl = welcomeview.pageControl 
    ...
}
而且,因为它是第一个视图,所以rootViewController是使用修改了viewDidLoad的BWwalkthrowhViewController设置的。因此,我在AppDelegate.swift中有一个用于设置此演练的func:

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屏幕截图,滚动条位于两个子视图之间:

你连接了吗

@IBOutlet var pageControl:UIPageControl?

在BWWalkthroughViewController中,是否在视图控制器中使用页面控制器


我通过在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)
}

bwalkthroughviewcontroller
类中添加以下函数

override func viewDidLayoutSubviews(){
    // Constraints
        let metricDict = ["w":view.bounds.size.width,"h":view.bounds.size.height]

        // - Generic cnst
        for vc in controllers {
            vc.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:[view(h)]", options:[], metrics: metricDict, views: ["view":vc.view]))
            vc.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:[view(w)]", options:[], metrics: metricDict, views: ["view":vc.view]))
            scrollview.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-0-[view]|", options:[], metrics: nil, views: ["view":vc.view,]))
        }
    }
addViewController
函数中删除以下行

// Constraints
let metricDict = ["w":vc.view.bounds.size.width,"h":vc.view.bounds.size.height]
    // - Generic cnst
        vc.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:[view(h)]", options:[], metrics: metricDict, views: ["view":vc.view]))
        vc.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:[view(w)]", options:[], metrics: metricDict, views: ["view":vc.view]))
        scrollview.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-0-[view]|", options:[], metrics: nil, views: ["view":vc.view,]))

我不能直接连接这个,因为我有我的自定义类。。。或者告诉我如何连接该^^^导航到BWWalkthroughViewController并找到我在上图中高亮显示的行。单击并拖动左侧边沟中的空点到视图控制器中的页面控制视图。@rednivlat,兄弟,你能帮我看一下我的问题吗?兄弟,你能帮我看一下我的问题吗?