【发布时间】:2017-04-25 13:23:24
【问题描述】:
我在控制器中有CollectionView 和TableView。我通过CollectionView 制作了segment control 并在controller 中实现scrollView delegate,如下所示:-
class MyViewController: UIViewController,UITableViewDelegate,UITableViewDataSource,UICollectionViewDelegate,UICollectionViewDataSource,UIScrollViewDelegate,UICollectionViewDelegateFlowLayout
我已经实现了scrollViewDidEndDecelerating,现在我想检测哪个组件滚动(tableView 或 collectionView)
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView)
{
//here i want to detect which component scrolling(tableView or collectionView)
if scrollView.contentOffset.x == 0
{
segmentControl.selectedSegmentIndex = 0
DispatchQueue.main.async{
self.colView.reloadData()
}
}
else if scrollView.contentOffset.x == view.frame.size.width
{
DispatchQueue.main.async{
self.colView.reloadData()
}
segmentControl.selectedSegmentIndex = 1
}
DispatchQueue.main.async{
let segAttributes: NSDictionary = [
NSForegroundColorAttributeName: UIColor.white,
NSFontAttributeName: UIFont.systemFont(ofSize: 12)
]
let segAttributes1: NSDictionary = [
NSForegroundColorAttributeName: UIColor.init(red: 247.0/255.0, green: 105.0/255.0, blue: 8.0/255.0, alpha: 1),
NSFontAttributeName: UIFont.systemFont(ofSize: 12)
]
self.segmentControl.setTitleTextAttributes(segAttributes1 as [NSObject : AnyObject], for: UIControlState.selected)
self.segmentControl.setTitleTextAttributes(segAttributes as [NSObject : AnyObject], for: UIControlState.normal)
self.tblVIewAmenities.reloadData()
self.tblViewRoomDetails.reloadData()
}
}
}
【问题讨论】:
-
带标签可以检测哪个组件在滚动
标签: ios swift uitableview uiscrollview uicollectionview