Popovers at Cell location๐ŸŽ

YaR Labยท2023๋…„ 12์›” 12์ผ
0

iOSย ๐ŸŽ

๋ชฉ๋ก ๋ณด๊ธฐ
26/26
post-thumbnail

Trouble ๐Ÿ“›

๐Ÿ”ฅ ๋ฌธ์ œ์ 

  • tableView ๋‚˜ collecitonView ์…€์—์„œ ํŠน์ • ์…€์˜ frame์—์„œ popover๋ฅผ ๋„์šฐ๊ธฐ ์œ„ํ•ด ์…€ ์ž์ฒด์— GestureRecognizer ์‚ฝ์ž…ํ•˜์˜€์Œ
  • Gesture๋ฅผ ์ธ์‹ํ•˜๋ฉด delegate๋ฅผ ํ†ตํ•ด colletionView๋‚˜ tableView์— frame์„ ๋„˜๊ฒจ์ฃผ์–ด pop ์˜ค๋ฒ„๋ฅผ ๋„์› ์Œ
  • ํ•˜์ง€๋งˆ ์ด๋ ‡๊ฒŒ frame์„ ๋„˜๊ฒจ์ฃผ๋ฉด Cell์ด init๋  ๋•Œ๋งŒ frame์ด ์—…๋ฐ์ดํŠธ๋˜๊ณ  reuse๋  ๋•Œ๋Š” update๋˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ์ด์ „ frame์— popover๋ฅผ ๋„์šฐ๋Š” ๋ฌธ์ œ๊ฐ€ ์ƒ๊น€

๐Ÿš’ ํ•ด๊ฒฐ์ฑ…

  • tableView ๋‚˜ collecitonView์ž์ฒด์— GestureRecognizer๋ฅผ ๋„ฃ์–ด์คŒ
  • ๊ทธ ํ›„๋กœ tableView๋Š” rectForRow ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์‚ฌ์šฉ์ž๊ฐ€ ํ„ฐ์น˜ํ•œ๊ณณ์˜ ์…€์„ ์ฐพ์„ ์ˆ˜ ์žˆ์Œ
  • collectionView๋Š” layoutAttributesForItem ๋ฉ”์„œ๋“œ์™€ convert ๋ฉ”์„œ๋“œ๋ฅผ ํ†ตํ•ด ์ •ํ™•ํ•œ cell์˜ ํ”„๋ ˆ์ž„์„ ์ฐพ์•„์˜ฌ ์ˆ˜ ์žˆ๋‹ค
let touchPoint = sender.location(in: sender.view)

guard let indexPath = collectionView.indexPathForItem(at: touchPoint) else {
    return
}

guard let theAttributes = collectionView.layoutAttributesForItem(at: indexPath) else {
    return
}

let cellFrame = collectionView.convert(theAttributes.frame, to: collectionView.superview)

์ถœ์ฒ˜๐Ÿ“š

๐ŸŽApple Docs: rectForRow(at:)
๐ŸŸ stackoverflow

0๊ฐœ์˜ ๋Œ“๊ธ€

๊ด€๋ จ ์ฑ„์šฉ ์ •๋ณด