I implemented the below code from Apple Documentation:if #available(iOS 13.4, *) {
func pointerInteraction(_ interaction: UIPointerInteraction, styleFor region: UIPointerRegion) -> UIPointerStyle? {
var pointerStyle: UIPointerStyle? = nil
if let interactionView = interaction.view {
let targetedPreview = UITargetedPreview(view: interactionView)
pointerStyle = UIPointerStyle(effect: UIPointerEffect.lift(targetedPreview))
}
return pointerStyle
}
}But it is gets applied on buttons on Navigation bar but not on UICollectionViewCell...I even tried this link: owncloud.org/news/of-mice-and-mobile-devices-implementing-mouse-interaction-in-ipados-13-4/But I don't know how to apply the same hover effect on UICollectionViewCell...!!!
Post
Replies
Boosts
Views
Activity
Hi,I added below print function but it doesn't print anything on mouse hover over cell...print("pointerInteraction view", interaction.view)I added the below code to cellForItemAt for CollectionViewCell, It gives me an error: Value of type 'CollectionViewCell' has no member 'view'customPointerInteraction(on: cell.view, pointerInteractionDelegate: self)
I was able to solve it myself...My code looks something like this now...customPointerInteraction(on: cell.self, pointerInteractionDelegate: self)
I tried moving 'let keyWindow' to 'SizeForItem' but it did not helped... it is still 'keyWindow?.bounds.size' is nil...I even tried printing 'keyWindow?.bounds.size' from 'ViewDidLoad' and it is still nil...Is it a Simulator problem?
Your code worked: 'self.view.bounds.size'
Actually I want to vary cell numbers horizontally once screen size increases. My cells are square in size so if size dimensions increases horizontal cell should increase in numbers to fit the area.
Is there any specific threshold/benchmark that I can code UICollectionView Cell for window width sizes for macOS e.g. As you know device-width in iOS and iPadOS ecosystem when you load your UI...
I have used your suggestion of fixed cell size for width and height, but at odd view sizes minimum spacing between two horizontal cells is unpredicatble and which is more than 10... How to manage this spacing between a cell while increasing horizontal cell count?
Code you shared creates three columns for every size. I want to increase column in numbers when size increases.I used your idea fixed cell size but it creates unmanageable space between two horizontal cells at certain sizes...
Can you showcase exact code with right options as I am not getting any help from autocomplete or online search...
I used your suggestion of 'if (sourceSection == destSection)' but user is able to still drag from section 1 to 0...
Also used your code for else statement but it never gets called.
I think answer should be Collection View 'Section' Specific.
As per requirement user should be able to only move cells within sections i.e. Section 1 cells should be rearranged within section 1 only..
I was able to solve it myself...
Thanks Again...
Hi,
I create UILabel by Adding it as a subview to header...
Here is my code for Header at '0'...
override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) - UICollectionReusableView {
let reusableview = UICollectionReusableView()
if (kind == UICollectionView.elementKindSectionHeader) {
print("section \(indexPath.section)")
if indexPath.section == 0 {
let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: collectionViewFirstHeaderFooterReuseIdentifier, for: indexPath)
headerView.backgroundColor = .clear
let headerUILabelText = UILabel()
headerUILabelText.textAlignment = .left
headerUILabelText.font = UIFont.systemFont(ofSize: 20, weight: .bold)
headerUILabelText.numberOfLines = 0
headerUILabelText.text = "Your Roll Number is \(NumberInteger). Your Exam Numbers are \(examNumbers(number: "\(NumberInteger)"))"
headerUILabelText.textColor = .darkGray
headerUILabelText.lineBreakMode = .byTruncatingTail
headerView.addSubview(headerUILabelText)
headerUILabelText.setMargins()
headerUILabelText.isHidden = false
headerUILabelText.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
headerUILabelText.leadingAnchor.constraint(equalTo: headerView.leadingAnchor),
headerUILabelText.trailingAnchor.constraint(equalTo: headerView.trailingAnchor),
headerUILabelText.centerXAnchor.constraint(equalTo: headerView.centerXAnchor),
headerUILabelText.centerYAnchor.constraint(equalTo: headerView.centerYAnchor),
headerUILabelText.topAnchor.constraint(equalTo: headerView.topAnchor),
headerUILabelText.rightAnchor.constraint(equalTo: headerView.rightAnchor),
headerUILabelText.bottomAnchor.constraint(equalTo: headerView.bottomAnchor),
headerUILabelText.leftAnchor.constraint(equalTo: headerView.leftAnchor),
headerUILabelText.widthAnchor.constraint(equalToConstant: headerView.frame.width),
headerUILabelText.heightAnchor.constraint(equalToConstant: headerView.frame.height)
])
return headerView
} else if indexPath.section == 1 {
let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: collectionViewSecondHeaderFooterReuseIdentifier, for: indexPath)
return headerView
} else {
return reusableview
}
}
@Claude31
I used solution similar to OOPer has given above and it solved the problem...
I used above code mentioned by me in individual View Controller in ViewDidLoad method... But I got this error: "Directly modifying a tab bar managed by a tab bar controller is not allowed."