// 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
}
}
전용 컨트롤러는 다른 뷰 컨트롤러를 제공 할 수 볼. 위임 패턴을 사용하여 위임 패턴을 사용할 수 있습니다.
이 프로토콜을 준수, 당신의 ViewController에서 ScheduleView에
var presentVCDelegate: PresentVCDelegate
을 속성을 추가 새로운 프로토콜
protocol PresentVCDelegate {
func presentVC()
}
를 만들고 자체로보기의 대리자를 설정
//in view will appear
view.presentVCDelegate = self
돈 프로토콜을 준수하는 것을 잊지 마십시오
extension ViewController: PresentVCDelegate {
func presentVC() {
//present your secondViewController here
}
}
마지막 ScheduleView 안에 당신의 touchEnd 방법에 위임 방법
self.presentVCDelegate.presentVC()
감사합니다. 그것은 작동합니다. – user3525889