[英]UIPopoverControl on UIButton inside UICollectionViewCell?
我有一個UICollectionView
,其中有許多UICollectionViewCell
,每個UICollectionViewCell
中都有一個UIButton
。 我想在用戶每次按下這些UIButton
之一時顯示一個UIPopoverController
。 但是,當我這樣做時, UIPopoverController
的位置遠不正確。 我的猜測是,這是由於我正在使用的CGRect
的翻譯問題CGRect
,但是我一生無法弄清楚如何糾正它。 在按下UIButton
時調用的選擇器內部,我有類似這樣的內容...
UIButton *detailsButton = (UIButton *)sender;
[self.popoverController presentPopoverFromRect:detailsButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
當我這樣做,但是,它每次出現被定位不管位置在同一地點, UIButton
和UICollectionViewCell
的內UICollectionView
。 有人可以給我一些關於如何在整個UICollectionView
轉換UIButton
位置的UICollectionView
嗎? 我想我需要detailsButton
的絕對位置,但是如何獲取它卻茫然。
謝謝你提供的所有幫助!
視圖的坐標是相對於其父視圖的坐標,而不是相對於屏幕的坐標。 因此,如果所有單元格都相同,則所有按鈕的detailsButton.frame
都將相同。
嘗試更改inView:
參數。
[self.popoverController presentPopoverFromRect:detailsButton.frame inView:detailsButton.superview permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.