我正在寻找一些建议如何在故事板中 swift 中创建侧边栏菜单或 xib 。
答案 0 :(得分:2)
我相信你可以从UISplitViewController开始形式 在iOS8中大幅更新。观看会议View Controller Advancements in iOS8和 Building Adaptive Apps with UIKit 细节。他们提供code example from second session (但不是第一个形成:/)。在这一点上,我觉得很自然 在iOS8中基于分割视图控制器制作这种UI。
结帐:Slide Sidebar Menu IOS 8 Swift
您还可以查看此教程: http://www.appcoda.com/sidebar-menu-swift/
这是一个很棒的教程,有一个例子。
答案 1 :(得分:1)
为我工作......
我创建了一个新的视图控制器作为“MenuViewController”,以及两个海关segues类。
要打开的第一个类,要关闭菜单的第二个类。
打开菜单:
import Foundation
import UIKit
class SegueFromLeft: UIStoryboardSegue {
override func perform() {
let src = self.source as UIViewController
let dst = self.destination as UIViewController
src.view.superview?.insertSubview(dst.view, aboveSubview: src.view)
dst.view.transform = CGAffineTransform(translationX: -src.view.frame.size.width, y: 0)
UIView.animate(withDuration: 0.25,
delay: 0.0,
options: UIViewAnimationOptions.curveEaseInOut,
animations: {
dst.view.transform = CGAffineTransform(translationX: 0, y: 0)
},
completion: { finished in
src.present(dst, animated: false, completion: nil)
}
)
}
}
关闭菜单:
import Foundation
import UIKit
class SegueFromRight: UIStoryboardSegue {
override func perform() {
let src = self.source as UIViewController
let dst = self.destination as UIViewController
src.view.superview?.insertSubview(dst.view, belowSubview: src.view)
src.view.transform = CGAffineTransform(translationX: 0, y: 0)
UIView.animate(withDuration: 0.25,
delay: 0.0,
options: UIViewAnimationOptions.curveEaseInOut,
animations: {
src.view.transform = CGAffineTransform(translationX: -src.view.frame.size.width, y: 0)
},
completion: { finished in
src.dismiss(animated: false, completion: nil)
}
)
}
}
本教程适用于从左到右的菜单,但如果您想要反方向,请更改:
-src.view.frame.size.width
为:
src.view.frame.size.width
我希望它对你有所帮助......