我有与UITableViewController
闪烁有关的问题。
此视频链接中对此进行了介绍。
我正在展示这样的 UITableViewController:
func balanceAction() {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "MainView")
presentView(view:controller)
}
fileprivate func presentView(view: UIViewController) {
(navigationDrawerController?.rootViewController as? ToolbarController)?.transition(to: view, duration: 0.3)
}
和来自lib的方法:
/**
A method to swap rootViewController objects.
- Parameter toViewController: The UIViewController to swap
with the active rootViewController.
- Parameter duration: A TimeInterval that sets the
animation duration of the transition.
- Parameter options: UIViewAnimationOptions thst are used
when animating the transition from the active rootViewController
to the toViewController.
- Parameter animations: An animation block that is executed during
the transition from the active rootViewController
to the toViewController.
- Parameter completion: A completion block that is execited after
the transition animation from the active rootViewController
to the toViewController has completed.
*/
open func transition(to viewController: UIViewController, duration: TimeInterval, options: UIViewAnimationOptions = [], animations: (() -> Void)? = nil, completion: ((Bool) -> Void)? = nil) {
rootViewController.willMove(toParentViewController: nil)
addChildViewController(viewController)
viewController.view.frame = rootViewController.view.bounds
transition(from: rootViewController,
to: viewController,
duration: duration,
options: options,
animations: animations) { [weak self, viewController = viewController, completion = completion] (result) in
guard let s = self else {
return
}
viewController.didMove(toParentViewController: s)
s.rootViewController.removeFromParentViewController()
s.rootViewController = viewController
s.rootViewController.view.clipsToBounds = true
s.rootViewController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
s.rootViewController.view.contentScaleFactor = Device.scale
completion?(result)
}
}
和MainView()
.
class MainView: UITableViewController {
var data = BalanceViewController()
open override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = Color.grey.lighten5
prepearTableView()
prepareToolbar()
}
private func prepearTableView() {
tableView.register(UINib(nibName: "BalanceCell", bundle: nil), forCellReuseIdentifier: "BalanceCell")
self.tableView.separatorStyle = UITableViewCellSeparatorStyle.none
self.tableView.dataSource = data
self.tableView.delegate = self
}
private func prepareToolbar() {
guard let tc = toolbarController else {
return
}
tc.toolbar.title = "Balance report"
tc.toolbar.detail = "Lifelong overall report"
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return balanceCellHeight
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
}
}