【发布时间】:2017-11-02 14:18:56
【问题描述】:
我想在xib中调用touchEnded函数时展示ViewController,但我不知道如何实现它。
这是我项目的一部分。
// ViewController.swift
class ViewController: UIViewController {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// add custom xib view (day view)
let view = Bundle.main.loadNibNamed("ScheduleView", owner: self, options: nil)?.first as! ScheduleView
view.frame = self.view.frame
self.view.addSubview(view)
}
}
// ScheduleView.swift
class ScheduleView.swift: UIView {
/*
// Only override draw() if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func draw(_ rect: CGRect) {
// Drawing code
}
*/
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
print("touchesBegan")
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event)
print("touchesEnd")
// move scene in here
// show secondViewController
}
}
// secondeViewController.swift
class secondeViewController.swift: UIViewController {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}
}
【问题讨论】:
标签: ios swift uiview uiviewcontroller presentviewcontroller