Swift - TabViewController与其中一个选项卡中的SwipeViewControler

时间:2017-02-14 21:38:42

标签: swift xcode viewcontroller

另一个新手快点来到这里。我希望我的应用程序在底部和内部的一个选项卡中有四个选项卡,我希望能够在两个“寻呼机”样式选项卡之间滑动。

我已经能够通过启动一个新的选项卡式应用程序并添加两个额外的视图控制器来使四个选项卡在底部工作。

I want the SwipeView inside of the Home tab

然后我尝试将一个SwipeViewController(https://github.com/fortmarek/SwipeViewController)添加到其中一个选项卡,但它工作但是它覆盖了入口点,所以我看到的是两个SwipeView选项卡,底部没有TabController选项卡。

!I want this inside of the Home tab] 1

我认为问题在于我的委托代码,因为它将self.window?.rootViewController设置为SwipViewController。删除该分配会使标签栏显示为备份,但它在“主页”选项卡内部为黑色,因此它仍然无法正常工作。

class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    let pageController = UIPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil)

    let navigationController = SecondViewController(rootViewController: pageController)
    self.window?.rootViewController = navigationController
    self.window?.makeKeyAndVisible()

    return true
}

我还尝试从故事板中获取“Home”选项卡的相应窗口,并将导航控制器设置为该窗口。

  let secondViewControllerWindow = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Home").view.window
    secondViewControllerWindow?.rootViewController = navigationController
    secondViewControllerWindow?.makeKeyAndVisible()

但是Home仍然是空的。这是由Home选项卡表示的ViewController代码,应该控制SwipViewController

import UIKit

class SecondViewController: SwipeViewController {

override func viewDidLoad() {
    super.viewDidLoad()

    let stb = UIStoryboard(name: "Main", bundle: nil)
    let page_one = stb.instantiateViewController(withIdentifier: "nba") as UIViewController
    let page_two = stb.instantiateViewController(withIdentifier: "mlb") as UIViewController
    setViewControllerArray([page_one, page_two])

    page_one.title = "NBA"
    page_two.title = "MLB"

    setFirstViewController(0)

    equalSpaces = true

    //setButtons(UIFont.systemFontOfSize(18), color: UIColor.blackColor())
    //setSelectionBar(80, height: 3, color: UIColor.blackColor())

    setButtonsOffset(40, bottomOffset: 5)


}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}
}

我的问题与其他问题相似,但我没有找到答案。

Using Page View Controller inside Tab Swift

Xcode 6 - Swift - Custom Tabbar with Navigation

1 个答案:

答案 0 :(得分:0)

我最近遇到了同样的问题,并且在这里找到了解决方案。 https://github.com/fortmarek/SwipeViewController/issues/26

我没有将代码放入didFinishLaunchingWithOptions中。 我试图在main.storyboard上工作。

我将PageViewController拖入其中,并将其设置为您的(SecondViewController)的RootView。 它对我有用。