Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

How to get ASCellNode's frame in it's container #2986

Closed
av0c0der opened this issue Feb 6, 2017 · 6 comments
Closed

How to get ASCellNode's frame in it's container #2986

av0c0der opened this issue Feb 6, 2017 · 6 comments

Comments

@av0c0der
Copy link

av0c0der commented Feb 6, 2017

If we get a cell from UICollectionView or UITableView it will have appropriate frame with right origin within the container, but origin point of ASCellNode that we got from ASCollectionNode or ASTableNode always equals to zero. I want to know this frame to change other subnode's frame in the container (ASColletionNode). Can I do this?

ASDK version: 2.0.2

@Adlai-Holler
Copy link
Contributor

Sure! You should convert the rect:

CGRect nodeFrame = [collectionNode convertRect:cellNode.bounds fromNode:cellNode]

@av0c0der
Copy link
Author

av0c0der commented Feb 7, 2017

func collectionNode(_ collectionNode: ASCollectionNode, didSelectItemAt indexPath: IndexPath) {
  if let cellNode = collectionNode.nodeForItem(at: indexPath) {
    let nodeFrame = collectionNode.convert(cellNode.bounds, from: cellNode)
    print(nodeFrame.origin) // This will be equal to 0.0, 0.0
  }
}

@fruitcoder
Copy link
Contributor

I actually get non zero values for:
collectionNode.convert(cellNode.bounds from: cellNode).origin = CGPoint(457.66, -10.0)

But I want to convert this frame to screen coordinates (for UIViewControllerPreviewing) but using
collectionNode.convert(cellNode.frame, to: nil) gives me (-457.66, 253)

This both doesn't make sense to me since in this example the view debugger gives me an origin of (620, 0) (300 width cells, 10 spacing, 3. cell) and the screen coordinates should be around (80,250). Is it because the collectionNode is inside another cell node (which is in an ASTableNode)?

@fruitcoder
Copy link
Contributor

@jauzee was your issue resolved? If not could you reopen it? Otherwise I'll open another issue

@av0c0der
Copy link
Author

av0c0der commented Jun 6, 2018

@fruitcoder sorry, I didn't see your message. Now I was trying to solve this problem again, because in 2.6 it still does exist and finished with this:

func previewingContext(_ previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {
    let collectionNode = node.collectionNode
    guard
      let indexPath = collectionNode.indexPathForItem(at: location),
      let targetCell = collectionNode.view.visibleCells
        .first(where: { $0.frame.contains(location) }) else {
        return nil
    }
    
    previewingContext.sourceRect = targetCell.frame
    
    ...
}

@abhigourking
Copy link

abhigourking commented Jan 18, 2021

@jauzee @Adlai-Holler @fruitcoder @levi @JoelMarcey This issue is closed without any proper solution.
Please have a look at my open issue similar to this problem.
#3357

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants