0
我设法以编程方式制作幻灯片菜单控制器。我正在尝试在tableViewController中添加一个转换,当你点击一个标签关闭菜单时,这个动画会让tableView全屏显示0.2秒,然后关闭菜单。这会给点时间改变点击按钮的视图,并且看起来不错。在didSelectRowAtIndexPath中做了。有用!幻灯片视图控制器
tableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0)
因为我只打开屏幕的菜单80%我移位单元的内容查看在屏幕的80%出现。当动画在didSelectRowAtIndexPath方法开始我转回到0,所以我不会看到一个空间上的tableView的左侧,像这样:
tableView.contentInset = UIEdgeInsetsMake(0, menuWidthGap, 0, -menuWidthGap)
现在,当我点击一次按钮仍然这样。当我再次单击该按钮以返回到contentView的初始状态时,我可以做些什么。
这是我的tableView:
import UIKit
class MenuLeftVC: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Initialize the window
let window = UIWindow.init(frame: UIScreen.main.bounds)
window.makeKeyAndVisible()
view.backgroundColor = UIColor.yellow
navigationController?.isNavigationBarHidden = true
tableView.dataSource = self
tableView.delegate = self
tableView.showsVerticalScrollIndicator = false
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "Cell")
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(true)
print("did apear")
tableView.contentInset = UIEdgeInsetsMake(0, menuWidthGap, 0, -menuWidthGap)
}
func selectCell() {
print("selected cell - >")
NotificationCenter.default.post(name: NSNotification.Name("SelectedCell"), object: nil)
}
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 20
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell")!
cell.contentView.reloadInputViews()
cell.isSelected = false
tableView.contentInset = UIEdgeInsetsMake(0, menuWidthGap, 0, -menuWidthGap)
cell.contentView.backgroundColor = UIColor.yellow
cell.textLabel?.text = "Daim Boy"
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let selectedCell:UITableViewCell = tableView.cellForRow(at: indexPath)!
selectedCell.contentView.backgroundColor = UIColor.red
selectedCell.isSelected = false
if selectedCell.isSelected == true {
print("selection")
if selectedCell.textLabel?.text == "Daim Boy" {
print("cell is selected")
UIView.animate(withDuration: 0.3, animations: {
tableView.contentInset = UIEdgeInsetsMake(0, menuWidthGap, 0, -menuWidthGap)
self.selectCell()
//selectedCell.isSelected = false
})
}
}
}
}
我不知道你怎么implemente d幻灯片,但它听起来像你可能想使用'UICollectionView'而不是'UITableView',因为它带来了免费的滑动和转换。 – shallowThought
我认为你应该看看视图控制器的转换。 – dasdom
无论如何感谢,但它与ViewController动画无关。我有2个内容视图。其中一个拥有一个菜单,另一个拥有一个视图控制器。当我按菜单项didSelectCell触发,我有那个动画,将移动contentView。我将放置完整的代码以便更好地理解。 –