I have a tableView
inside a scrollView
.
I want when I scroll tableView
, the outer scrollView
will also scroll.
Currently, when I scroll tableView
, the outer scrollView
not scroll.
So how to do this?
//Declare the view which is going to be added as scrolling view, for instance
let requiredView = UIScrollView()
//Add your required view as subview of tableview backgroundView view like as
tableView.backgroundView = UIView()
tableView.backgroundView?.addSubview(requiredView)
//After that control the frame of requiredHeaderView in scrollViewDidScroll delegate method like
func scrollViewDidScroll(scrollView: UIScrollView) {
let per:CGFloat = 60 //percentage of required view to move on while moving collection view
let deductValue = CGFloat(per / 100 * requiredView.frame.size.height)
let offset = (-(per/100)) * (scrollView.contentOffset.y)
let value = offset - deductValue
self.requiredView.contentOffset = CGPointMake(1.0, value)
}
scrollView
, can't you simple add aheaderView
to thetableView
?scrollView
is depend on thetableView
inside it.