Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convertPoint:toView: in landscape mode giving wrong values

I have a view which is created in landscape mode (long after rotation etc.).
In this view, I want to find a point relative to the main window.
The following code works in portrait mode, but in landscappe it still returns values as if it were in portrait.

CGPoint ptRelativeToWindow = [self convertPoint:self.bounds.origin toView:nil]; 

Solved

This solved the problem and gives the right coordinates:

[self convertPoint:self.bounds.origin toView:[UIApplication sharedApplication].keyWindow.rootViewController.view]; 
like image 700
Egil Avatar asked Jun 23 '11 10:06

Egil


Video Answer


1 Answers

You can't use main window to calculate relative coordinates. Main window receives rotation events and passes them onto controllers which means it doesn't change the size itself (always has the same portrait bounds). That's why the solution you found makes sense: you find the coordinates relative to the view of the root controller which does receive rotation events and changes its size accordingly

like image 71
Nick Avatar answered Sep 20 '22 09:09

Nick