我正在使用xcode 8.0&斯威夫特3。
以下是我的问题概述:
以下是我需要解决的问题:
我需要touchesBegan在点击滚动视图时被触发。我已将“.cancelsTouchesInView = false”添加到手势中。
此外,滚动视图上的缩放/平移手势需要保持不变。因此,在scrollview&里面的imageview。
此see attached image显示布局& viewcontroller swift文件。 黄色区域是滚动视图。 (里面有“内心”)
但是,为了快速参考,这是我的代码:
import UIKit
var tap = UITapGestureRecognizer()
class ViewController: UIViewController, UIScrollViewDelegate, UIGestureRecognizerDelegate {
@IBOutlet weak var scroller: UIScrollView!
@IBOutlet weak var insidepic: UIImageView!
@IBOutlet weak var outsidepic: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
scroller.minimumZoomScale = 1
scroller.maximumZoomScale = 6
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
tap = UITapGestureRecognizer(target: self, action: #selector(self.handleTap))
tap.numberOfTapsRequired = 1;
tap.numberOfTouchesRequired = 1;
tap.delegate = self
tap.cancelsTouchesInView = false
scroller.addGestureRecognizer(tap)
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
print("Touches Began")
}
func handleTap(){
print("Tap Gesture Received")
}
func viewForZooming(in scrollView: UIScrollView) -> UIView? {
return insidepic
}
}
非常感谢您提供任何帮助或洞察力!