Swift 3 /如何使用UIViewController的UINavigationBar重叠Root的UINavigationBar

时间:2016-10-22 01:48:35

标签: ios swift

我试图从Tinder重新创建导航行为。为此,我已将Framework delivering the NavigationBar翻译成Swift 3。

测试应用非常简单。如果有人有兴趣,我已经创建了一个测试git project

class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?
var controller: SLPagingViewSwift!
var nav: UINavigationController?
var home: ViewController?

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


    window = UIWindow(frame: UIScreen.main.bounds)
    let orange = UIColor(red: 255/255, green: 69.0/255, blue: 0.0/255, alpha: 1.0)
    let gray = UIColor(red: 0.84, green: 0.84, blue: 0.84, alpha: 1.0)

    let stb = UIStoryboard(name: "Main", bundle: nil)
    self.home = stb.instantiateViewController(withIdentifier: "ViewController") as? ViewController
    let vc2 = ViewController()
    vc2.view.backgroundColor = .red
    let vc3 = ViewController()
    vc3.view.backgroundColor = .blue


    var homeBtn = UIImage(named: "profile")
    homeBtn = homeBtn?.withRenderingMode(.alwaysTemplate)
    var vc2Btn = UIImage(named: "gear")
    vc2Btn = vc2Btn?.withRenderingMode(.alwaysTemplate)
    var vc3Btn = UIImage(named: "chat")
    vc3Btn = vc3Btn?.withRenderingMode(.alwaysTemplate)

    let items = [UIImageView(image: homeBtn),
                 UIImageView(image: vc2Btn),
                 UIImageView(image: vc3Btn)]

    let controllers = [self.home!,
                       vc2,
                       vc3] as [UIViewController]

    self.controller = SLPagingViewSwift(items: items, controllers: controllers, showPageControl: false)

    self.controller.pagingViewMoving = ({ subviews in
        if let imageViews = subviews as? [UIImageView] {
            for imgView in imageViews {
                var c = gray
                let originX = Double(imgView.frame.origin.x)

                if (originX > 45 && originX < 145) {
                    c = self.gradient(originX, topX: 46, bottomX: 144, initC: orange, goal: gray)
                }
                else if (originX > 145 && originX < 245) {
                    c = self.gradient(originX, topX: 146, bottomX: 244, initC: gray, goal: orange)
                }
                else if(originX == 145){
                    c = orange
                }
                imgView.tintColor = c
            }
        }
    })

    self.nav = UINavigationController(rootViewController: self.controller)
    self.window?.rootViewController = self.nav
    self.window?.backgroundColor = UIColor.black
    self.window?.makeKeyAndVisible()

    return true

}

在我的UIViewController中,我想要在UIViewController堆栈中推送新的UINavigationController(以使后退按钮和后滑动),一旦单击一个单元格。

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    let stb = UIStoryboard(name: "Main", bundle: nil)
    let vc = stb.instantiateViewController(withIdentifier: "SegueVC")
    let appDelegate = UIApplication.shared.delegate as! AppDelegate

    appDelegate.controller?.navigationController?.pushViewController(vc, animated: true)
    //appDelegate.nav?.pushViewController(vc, animated: true)
}

问题是,SegueVC与Root具有相同的UINavigationBar

enter image description here

基本上我希望UINavigationBar的{​​{1}}与根控制器的栏重叠以实现此目的:

enter image description here

如果我在SegueVCcontroller上推送SegueVC,则没有任何区别。

nav

AppDelegate中显示的结构:appDelegate.controller?.navigationController?.pushViewController(vc, animated: true) //appDelegate.nav?.pushViewController(vc, animated: true) nav的{​​{1}}和rootViewController的{​​{1}}。

window

我正在考虑在导航堆栈外面展示SegueVC动画,但后来我错过了内置后退按钮和滑动后退手势。我有什么选择?非常感谢帮助。

1 个答案:

答案 0 :(得分:1)

你可以通过设置一个容器到你的mainVC并相应地移动它来做到这一点...我相信推特动画很容易实现。我在我的项目中使用相同类型的动画过渡。

我强烈建议在giithub中检查这个项目 https://github.com/evnaz/ENSwiftSideMenu并在此链接Change Status Bar Color in Real Time

中查看我的回答

如果你想从你的帖子实现你的第一次截屏。我相信你可以轻松隐藏你的statusBar和navigationBar。并放置导航栏位置的UIView顶部检查我的答案Swift Navigation bar background color white does not work并放置一个uiview lager然后storyBoard就像view.frame.width + 100(无论大小适合你)并使用UIView(你可以使用)在检测到swipeGesture时,容器to)偏移位置。

点击此链接与推特动画https://github.com/ThornTechPublic/InteractiveSlideOutMenu https://github.com/ThornTechPublic/LeftSlideoutMenu

相关

注意:以上,根据我和我之间的早期对话回答问题所有者。