Swift UITableViewCell 子视图不注册点击
Swift UITableViewCell subview do not register tap
背景: 我正在制作一个日历,为此我正在组合一个 UITableView 和一个 UICollectionViews。 UITableView 持有月份单元格。每个月 UITableViewCell 持有一个 UICollectionView with UICollectionViewCell 天。
问题: UICollectionViewCells 不可点击。
我可以通过在月 UITableViewCell 中调用 self.bringSubviewToFront(self.collectionView) 来解决这个问题。但是,这会使 UITableView 无法滚动,因为 collectionView 现在是顶部视图。
因此,我可以在能够滚动 UITableView 或能够单击 UICollectionView 之间进行选择。
我的尝试: 我试图在点击发生之前捕获它,并将 collectionView 置于最前面,然后再将其放回原位。虽然不是一个好的解决方案:
//In UITableViewCell class
//UIGestureRecognizerDelegate
//Bring collectionView to front before tap
override func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {
self.bringSubviewToFront(self.collectionView)
return true
}
//UIScrollViewDelegate
//Bring collectionView to back again
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
self.sendSubviewToBack(self.collectionView)
//Do stuff
}
问题: 我怎样才能实现既能滚动又能点击 UICollectionView 而无需在点击之间返回和转发视图?有没有办法让 UICollectionView 在前面,同时让 UITableView 可以滚动?
具有相同滚动方向的嵌套 UIScrollView 违反 Apple 的人机界面指南,您的应用甚至可能因此而被拒绝,因此请尝试禁用 UICollectionView 的滚动。
希望对您有所帮助。
背景: 我正在制作一个日历,为此我正在组合一个 UITableView 和一个 UICollectionViews。 UITableView 持有月份单元格。每个月 UITableViewCell 持有一个 UICollectionView with UICollectionViewCell 天。
问题: UICollectionViewCells 不可点击。 我可以通过在月 UITableViewCell 中调用 self.bringSubviewToFront(self.collectionView) 来解决这个问题。但是,这会使 UITableView 无法滚动,因为 collectionView 现在是顶部视图。
因此,我可以在能够滚动 UITableView 或能够单击 UICollectionView 之间进行选择。
我的尝试: 我试图在点击发生之前捕获它,并将 collectionView 置于最前面,然后再将其放回原位。虽然不是一个好的解决方案:
//In UITableViewCell class
//UIGestureRecognizerDelegate
//Bring collectionView to front before tap
override func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {
self.bringSubviewToFront(self.collectionView)
return true
}
//UIScrollViewDelegate
//Bring collectionView to back again
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
self.sendSubviewToBack(self.collectionView)
//Do stuff
}
问题: 我怎样才能实现既能滚动又能点击 UICollectionView 而无需在点击之间返回和转发视图?有没有办法让 UICollectionView 在前面,同时让 UITableView 可以滚动?
具有相同滚动方向的嵌套 UIScrollView 违反 Apple 的人机界面指南,您的应用甚至可能因此而被拒绝,因此请尝试禁用 UICollectionView 的滚动。
希望对您有所帮助。