我正在使用the Hero library在视图控制器之间进行转换。
第一个视图控制器:
class ViewController: UIViewController {
@IBOutlet weak var tableView: UITableView!
var people = [Person]()
override func viewDidLoad() {
super.viewDidLoad()
hero.isEnabled = true
hero.modalAnimationType = .push(direction: .right)
}
@IBAction func handleButton(){
let view = self.storyboard?.instantiateViewController(withIdentifier: "secondVC") as! UIViewController
present(view, animated: true, completion: nil)
}
}
第二个视图控制器:
class Second: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
hero.isEnabled = true
// Do any additional setup after loading the view.
}
@IBAction func handleBackButton(){
hero.modalAnimationType = .push(direction: .left)
hero.dismissViewController()
}
}
它显示没有任何动画的新视图。当我关闭第二个控制器时,它将应用正确的动画。如何使用动画显示第二个视图?
答案 0 :(得分:1)
好的找到了解决方案。 在第一种情况下,我有:
@IBAction func handleButton() {
let view = self.storyboard?.instantiateViewController(withIdentifier: "secondVC") as! UIViewController
present(view, animated: true, completion: nil)
}
我必须在视图上设置动画。
@IBAction func handleButton() {
let view = self.storyboard?.instantiateViewController(withIdentifier: "secondVC") as! UIViewController
view.hero.modalAnimationType = .push(direction: .right)
present(view, animated: true, completion: nil)
}
作品
答案 1 :(得分:0)
通过设置Hero扩展名heroModalAnimationType
:
hero.heroModalAnimationType = .push(direction: .right)
请勿忘记使用Hero.shared
对象的方法停用转换的默认动画:
func disableDefaultAnimationForNextTransition()
func setDefaultAnimationForNextTransition(_ animation: HeroDefaultAnimationType)