1

As the question says,I want to get the position of a uibutton as shown in the image and I have to show a pop up menu from that uibutton(in the tableviews view).

I went through Question1 and Question2.But these are giving me different locations.

I use the code

    CGRect windowRect = [_tableView convertRect:button.frame fromView:tempCell];

temp cell is my selected cell.

I am using kxMenu for popUp menu,and I use the following code.

[KxMenu showMenuInView:_tableView
              fromRect:windowRect
             menuItems:menuItems];

So,I need to get the windowRect correctly.Anybody have any idea?

enter image description here

enter image description here

Community
  • 1
  • 1
abhimuralidharan
  • 5,752
  • 5
  • 46
  • 70
  • What did you use the method in Question 1 you linked? It looks like it should help you when used like this : `CGRect windowRect = [button convertRect:button.bounds toView:nil];` – Losiowaty Nov 25 '15 at 11:16
  • i use this code to get and seems correct `CGPoint windowPoint = [button convertPoint:button.bounds.origin toView:self.view];` (using this in scrollview) – Tj3n Nov 25 '15 at 11:21

2 Answers2

2

If you use

 [_tableView convertRect:button.frame fromView:tempCell];

It will convert frame of the button wrt tempcell to button frame wrt _tableView

If you want to get the frame of button wrt the window, you should do either

 [button convertRect:button.bounds toView:nil];

or

 [button.superView convertRect:button.frame toView:nil];
Johnykutty
  • 12,091
  • 13
  • 59
  • 100
1

By default, the nestedView.frame will give you the origin points respective to the immediate parent. Here is the Swift 5 version of this answer:

let frame: CGRect? = nestedView.superview?.convert(nestedView.frame, to: nil)

Objective-C version is as follows:

 CGRect frame = [nestedView.superView convertRect:nestedView.frame toView:nil];

This will give you the frame of the nestedView relative to the superview's superview. Hope this helps.

Shoaib A
  • 63
  • 7
  • looks like the correct solution, but the OP did ask for Obj-C. Should be trivial for them to them convert however – Brian Jul 05 '22 at 21:47