ios - 如何滑出侧边菜单栏?在 swift

标签 ios swift xcode swift3

如何在向左滑动时滑出侧边菜单栏?以及点击collectionView时如何自动滑出?我正在使用 tableView 和约束,我对该约束的导出是 rightMargin。

import UIKit
import ViewPagerController

class OptionTableViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

    @IBOutlet weak var rightMargin: NSLayoutConstraint!
    @IBOutlet weak var optionTableView: UITableView!

let option = ["LOG IN","SIGN UP","EDIT PROFILE", "LOG OUT"]
let storyBoardId = ["LogInViewController","SignUpViewController","UserEditPageViewController", "None"]

override func viewDidLoad() {
    super.viewDidLoad()

  var appearance = ViewPagerControllerAppearance()
  appearance.tabMenuAppearance.backgroundColor = UIColor.black

    let screenWidth = UIScreen.main.bounds.width
    rightMargin.constant = screenWidth
}
 override func viewDidAppear(_ animated: Bool) {

    super.viewDidAppear(animated)
    self.rightMargin.constant = 100

    UIView.animate(withDuration: 0.3 , animations: {
           self.view.layoutIfNeeded()
   })
}
override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()

}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return option.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

      let cell = optionTableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
    cell.textLabel?.text = option[indexPath.row]
    cell.textLabel?.font = UIFont(name: "Arial", size: 10)
        return cell
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    if let logInViewController = storyboard?.instantiateViewController(withIdentifier: storyBoardId[indexPath.row]) {
        navigationController?.pushViewController(logInViewController, animated: true)
    }
}
}

SlideInMenu

最佳答案

这些将让您滑动以打开您自己的选项。

override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
    return true
}

override func tableView(_ tableView: UITableView, editActionsForRowAt: IndexPath) -> [UITableViewRowAction]? {
let more = UITableViewRowAction(style: .normal, title: "More") { action, index in
    print("more button tapped")
}
more.backgroundColor = .lightGray

let favorite = UITableViewRowAction(style: .normal, title: "Favorite") { action, index in
    print("favorite button tapped")
}
favorite.backgroundColor = .orange

let share = UITableViewRowAction(style: .normal, title: "Share") { action, index in
    print("share button tapped")
}
share.backgroundColor = .blue

return [share, favorite, more]
 }

关于ios - 如何滑出侧边菜单栏?在 swift ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41748042/

相关文章:

ios - 在 UISegmentedControl 中换行文本 (iOS 9+)

ios - 如何使用核心蓝牙框架在最小化模式下扫描 'Lower Energy Bluetooth Device'?

复杂应用程序中的 iOS 事件处理

ios - 在 Swift 中使用 SWRevealViewController 手动 segue

ios - 尝试在设备上从 Xcode 测试应用程序时出错

ios - UITableViewController 中的 UIActivityIndi​​catorView 与 UITableView 在同一层次结构中

ios - imagePickerController 选择照片时出错

ios - 安全地更改 NSLayoutConstraint 常量值

c++ - 我在 mac os(英特尔芯片)上构建 opencv 项目时遇到此错误

c++ - 为什么很难找到 C++ 3d 游戏教程