如何使用委派模式
import UIKit
protocol PhotoViewDelegate{
func onTouchUpInside(aTouchendPoint:CGPoint)
}var delegate:PhotoViewDelegate?override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
let _touch:UITouch = touches.first!
let _touchendPoint:CGPoint = _touch.locationInView(self)
if _touchendPoint.x > 0 && _touchendPoint.x < self.bounds.width && _touchendPoint.y > 0 && _touchendPoint.y < self.bounds.height {
self.delegate?.onTouchUpInside(_touchendPoint)
}
}class MainViewController: UIViewController,PhotoViewDelegate {
func onTouchUpInside(aTouchendPoint: CGPoint) {
print("onTouchUpInside:\(aTouchendPoint)")
}
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.whiteColor()
let _photoView:PhotoView = PhotoView()
_photoView.frame = CGRectMake(10, 10, 100, 100)
self.view.addSubview(_photoView)
_photoView.delegate = self
}
//以下略Last updated