0

Basically, i have put accessory view on top of the keyborad, inside that view i have view, for which i need the the position, but relative to whole screen (like i am putting it on the whole screen) and not the superview?

I kinda tried it like this:,

How to get the absolute coordinates of a view

but to no avail.

Community
  • 1
  • 1
MegaManX
  • 8,766
  • 12
  • 51
  • 83
  • Update your question with the actual code you tried to use and explain the problem with the result. – rmaddy Apr 07 '16 at 15:27

1 Answers1

1

You can convert a frame (CGRect) or a point (CGPoint) from its superview's coordinate system to another view's coordinate system. All these methods are instance methods of UIView

For example:

let convertedRect = superview.convertRect(subview.frame, toView: anotherView)

In your case, you might try something like this:

let cRect = keyboardAccessoryView.convertRect(accessorySubview.frame, toView: self.view)

Note that this will convert the subview (whose frame is in the keyboardAccessory's coordinate space) to the current viewController's view's coordinate system.

If you want it in terms of the entire screen, try this:

let coordinateSpace = UIScreen.mainScreen().coordinateSpace
kbAccessoryView.convertRect(subview.frame, toCoordinateSpace: coordinateSpace)
Vinod Vishwanath
  • 5,821
  • 2
  • 26
  • 40