简体   繁体   English

iOS应用中的滑出菜单(快速)

[英]Slide-out menu in iOS app (swift)

I'm trying to build my own slide out menu in swift, but I'm having some troubles. 我正在尝试快速建立自己的滑出菜单,但遇到了一些麻烦。 Now, I coded a function that change the view.frame.origin.x so that I got my view to slide on the right. 现在,我编写了一个更改view.frame.origin.x的函数,以便使视图在右侧滑动。 Now, I added a subview at index: 0 and I want to make it show when I slide the main view (content) out. 现在,我在索引:0处添加了一个子视图,当我将主视图(内容)滑出时,我想使其显示。

let navView: NavigationViewController = self.storyboard?.instantiateViewControllerWithIdentifier("navView") as NavigationViewController

    view.insertSubview(navView.view, atIndex: 0)
    addChildViewController(navView)
    navView.didMoveToParentViewController(self)

And that's what happen when I click on the menu logo (at the top-left corner): 这就是我单击菜单徽标(在左上角)时发生的情况:

    @IBAction func showMenu(sender: AnyObject) {
    println("showMenu")
    if !self.menuIsOpen{
    UIView.animateWithDuration(0.5, delay: 0, usingSpringWithDamping: 1.0, initialSpringVelocity: 0, options: .CurveEaseInOut, animations: { () -> Void in
        self.view.frame.origin.x = 150
        }) { (isHappen: Bool) -> Void in
            if isHappen {
                println("OpenedUp!")
                self.menuIsOpen = true
            }
        }
    } else {
        UIView.animateWithDuration(0.5, delay: 0, usingSpringWithDamping: 1.0, initialSpringVelocity: 0, options: .CurveEaseInOut, animations: { () -> Void in
            self.view.frame.origin.x = 0
            }) { (isHappen: Bool) -> Void in
                if isHappen {
                    println("Closed!")
                    self.menuIsOpen = false
                }
        }
    }
}

So, now, this works but I suppose that the subview slides together with the rest of the main view. 因此,现在这可行,但是我认为子视图与主视图的其余部分一起滑动。 How can I make the navigationView not to hide? 如何使NavigationView不隐藏? Or better, to stay there (I mean with the origin.x: 0) 或更好地留在那里(我的意思是origin.x:0)

您能否拥有一个与视图控制器(1)关联的导航视图,然后将滑出菜单视图控制器(2)置于该视图控制器(vc1.addSubview(vc2.view))中?然后,您只需保留视图控制器( 1)的导航栏向上,并且视图控制器(2)将位于其中,因此它不会滑动视图控制器(1)的导航栏。

I know I'm a bit late, but in case anyone else has the same problem: I've implemented a similar mechanic on an app I'm currently working on. 我知道我来晚了,但是万一其他人遇到了同样的问题:我在当前正在使用的应用程序上实现了类似的机制。 To achieve it I used custom interactive transitions, which were introduced in iOS7. 为此,我使用了自定义的交互式过渡,该过渡在iOS7中引入。 I would recommend checking out the following links: 我建议您查看以下链接:

Hope that helps. 希望能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM