let scrollPoint: CGPoint = (sender as AnyObject).location(in: sender.view.superview)
Cannot call value of non-function type 'CGFloat'
import UIKit
class MyViewController: UIViewController {
@IBOutlet weak var scrollView: UIScrollView!
var slider = UIView()
override func viewDidLoad() {
super.viewDidLoad()
scrollView.contentSize = CGSize(width: scrollView.frame.size.width*2, height: scrollView.frame.size.height)
scrollView.backgroundColor = UIColor.lightGray
var panRecognizer = UIPanGestureRecognizer(target: self, action: #selector(move))
panRecognizer.minimumNumberOfTouches = 1
panRecognizer.maximumNumberOfTouches = 1
panRecognizer.delegate = self as! UIGestureRecognizerDelegate
slider.frame = CGRect(x: 30 + 30*i, y: 30 + 60*i , width: 50, height: 50)
slider.backgroundColor = UIColor.yellow
scrollView.addSubview(slider)
slider.addGestureRecognizer(panRecognizer)
}
@objc func move(_ sender: Any) {
if (sender as? UIPanGestureRecognizer)?.state == .changed {
// This will return you location in view
let currentPoint: CGPoint = (sender as AnyObject).location(in: view)
// This will return you location in Scrollview
let scrollPoint: CGPoint = (sender as AnyObject).location(in: sender.view.superview)
}
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesMoved(touches, with: event)
let touch: UITouch = touches.first as! UITouch
var newCoord = touch.location(in: self.view)
slider.frame = CGRect(origin: CGPoint(x: newCoord.x , y: newCoord.y, size: slider.frame.size)
}//end of func
}//end of class
class ChartViewController: UIViewController {
@IBOutlet weak var chartAreaScrollView: UIScrollView! // First UIScrollView
@IBOutlet weak var timeScrollView: UIScrollView! // Second UI ScrollView
override func viewDidLoad() {
super.viewDidLoad()
chartAreaScrollView.delegate = self as! UIScrollViewDelegate
timeScrollView.delegate = self as! UIScrollViewDelegate
}
extension ChartViewController: UIScrollViewDelegate {// Сообщение (Declaration is only valid at file scope)
func scrollViewDidScroll(scrollView: UIScrollView) {
self.chartAreaScrollView.contentOffset = scrollView.contentOffset
self.timeScrollView.contentOffset = scrollView.contentOffset
}
}
}