CopyPastor

Detecting plagiarism made easy.

Score: 2; Reported for: String similarity, Exact paragraph match Open both answers

Possible Plagiarism

Reposted on 2019-03-10
by Mendy Barouk

Original Post

Original - Posted on 2019-03-10
by Mendy Barouk



            
Present in both answers; Present only in the new answer; Present only in the old answer;

You can add `func indexPathForSupplementaryElement(ofKind kind: String, at point: CGPoint) -> IndexPath?` method in extension of `UICollectionView`
extension UICollectionView { func indexPathForSupplementaryElement(ofKind kind: String, at point: CGPoint) -> IndexPath? { let targetRect = CGRect(origin: point, size: CGSize(width: 0.1, height: 0.1)) guard let attributes = collectionViewLayout.layoutAttributesForElements(in: targetRect) else { return nil } return attributes.filter { $0.representedElementCategory == .supplementaryView && $0.representedElementKind == kind }.first?.indexPath } }
and use this in your `UIViewController` for example like this
@IBAction func didSelectHeader(sender: UIView, forEvent event: UIEvent) { guard let point = event.allTouches?.first?.location(in: collectionView) ?? sender.superview?.convert(sender.center, to: collectionView) else { return } guard let indexPath = collectionView.indexPathForSupplementaryElement(ofKind: UICollectionView.elementKindSectionHeader, at: point) else { return } // do something with the indexPath }
the `indexPath.item` in our case is every time 0 but the indexPath.section is different, depending on the location of the header relative to the section of the `collectionView`
You can add `func indexPathForSupplementaryElement(ofKind kind: String, at point: CGPoint) -> IndexPath?` method in extension of `UICollectionView`
extension UICollectionView { func indexPathForSupplementaryElement(ofKind kind: String, at point: CGPoint) -> IndexPath? { let targetRect = CGRect(origin: point, size: CGSize(width: 0.1, height: 0.1)) guard let attributes = collectionViewLayout.layoutAttributesForElements(in: targetRect) else { return nil } return attributes.filter { $0.representedElementCategory == .supplementaryView && $0.representedElementKind == kind }.first?.indexPath } }
and use this in your `UIViewController` for example like this
@IBAction func didSelectHeader(sender: UIView, forEvent event: UIEvent) { guard let point = event.allTouches?.first?.location(in: collectionView) ?? sender.superview?.convert(sender.center, to: collectionView) else { return } guard let indexPath = collectionView.indexPathForSupplementaryElement(ofKind: UICollectionView.elementKindSectionHeader, at: point) else { return } // do something with the indexPath }
the `indexPath.item` in our case is every time 0 but the indexPath.section is different, depending on the location of the header relative to the section of the `collectionView`

        
Present in both answers; Present only in the new answer; Present only in the old answer;