How to get subview position in my UITableViewCell with respect to the whole window?

I know convertRect:toRect is the key, but I'm not sure what to call it. I have a subclass of my cell, and I want its position in the entire application window.

I need to know this when I click on this button (subview) in the target action method. I have to call the convertRect:toRect in the cell, I suppose, in order to get the correct coordinates, but in this method I have nothing to do with the cell itself.

Am I going up the supervisor hierarchy? This seems rude, because I'm not quite sure what I will get, since it is embedded in the contentView in the cell, and Apple does ridiculous things with their private subtitles and something else.

the code:

 @IBAction buttonPressed(sender: UIButton) { // This button got the callback that it was pressed. It in a cell. I need to convert its rect to that of the window here. I need the coordinate system it calculated from (the cell) which I'm not sure of how to easily do in a target action callback. } 
+5
source share
1 answer

This is actually very simple:

 CGRect windowRect = [someSubview convertRect:someSubview.bounds toView:nil]; 

Assuming you have a button handler:

 - (void)someButtonHandler:(id)sender { UIButton *button = sender; // do your stuff CGRect windowRect = [button convertRect:button.bounds toView:nil]; } 

Of course, this is even easier if your method is configured as:

 - (void)someButtonHandler:(UIButton *)button { } 
+7
source

Source: https://habr.com/ru/post/1209680/


All Articles