Get frame for UITableViewCellAccessoryType

ぐ巨炮叔叔 提交于 2019-12-11 13:56:18

问题


I want to present a popover. Currently I can retrieve the frame of the whole cell (as described here). Is it possible to get the frame of the accessory (UITableViewCellAccessoryType)?

I want to retrieve the value in accessoryButtonTappedForRowWithIndexPath or didSelectRowAtIndexPath.


回答1:


in didSelectRowAtIndexPath

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
CGRect accessoryRect = cell.accessoryView.frame;



回答2:


The best I can come up with is to calculate the frame with fixed sizes. First you get the cell's frame with rectForRowAtIndexPath. Than you calculate the accessoryType frame. In my case I can give C# code, but you can translate it to Objective-C easily or roll your own solution:

int detailDisclosureSize = 24;
RectangleF accessoryPosition = new RectangleF(cellPosition.X + cellPosition.Width - detailDisclosureSize * 2.45f, cellPosition.Y + cellPosition.Height/2 - detailDisclosureSize/2, detailDisclosureSize, detailDisclosureSize);

cellPosition is the result from rectForRowAtIndexPath. Now you can translate it to the real coordinates with convertRect:toView:.

But the solution won't work if a new screen size comes out. Since there is currently no other solution I'll go with this or the whole cell size.



来源:https://stackoverflow.com/questions/26509740/get-frame-for-uitableviewcellaccessorytype

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!