App is in Landscape Mode, but main UIWindow still thinks it’s portrait.

19 views
Skip to first unread message

Joshua Garnham

unread,
Apr 22, 2010, 11:35:57 AM4/22/10
to coco...@lists.apple.com
My App runs in landscape mode and I have been converting a CGPoint
to the main UIWindow's co-ordinate system.


I decided to check this was
working all correctly by adding a couple of NSLog's to return the
Co-Ordinates before and after it was converted and what I noticed was
that before it was converted the
Co-Ordinates were correct for Landscape mode but after conversion to
the UIWindow's co-ordinate system the co-ordinates changed as if the
iPhone was in portrait mode.


Code and Debugger results are as follows.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeLeft];
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
currentTouch = [touch locationInView:self.view];

NSLog(@"User tapped at %@", NSStringFromCGPoint(currentTouch));

CGPoint CPT = [self.view convertPoint:currentTouch toView:nil];
NSLog(@"User tapped at %@", NSStringFromCGPoint(CPT));

}

Debugger:
2010-04-21 16:39:35.199 InSight[31366:207] User tapped at {418, -6}
2010-04-21 16:39:35.200 InSight[31366:207] Point 0x1.a2p+8, -0x1.8p+2
2010-04-21 16:39:35.201 InSight[31366:207] Point 0x1.a2fffffffap-1034, -0x1.8p+2
2010-04-21 16:39:35.202 InSight[31366:207] Point 418, -6
2010-04-21 16:39:35.204 InSight[31366:207] User tapped at {38, 24}
In my plist I also have this. Initial interface orientation |Landscape (left home button)




_______________________________________________

Cocoa-dev mailing list (Coco...@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/cocoa-dev-garchive-98506%40googlegroups.com

This email sent to cocoa-dev-ga...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "cocoa-dev" group.
To post to this group, send email to coco...@googlegroups.com.
To unsubscribe from this group, send email to cocoa-dev+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cocoa-dev?hl=en.

David Duncan

unread,
Apr 22, 2010, 12:12:08 PM4/22/10
to Joshua Garnham, coco...@lists.apple.com
On Apr 22, 2010, at 8:35 AM, Joshua Garnham wrote:

> My App runs in landscape mode and I have been converting a CGPoint
> to the main UIWindow's co-ordinate system.

Why? There should generally be no need to convert to the window's coordinate system.

> UIWindow's co-ordinate system the co-ordinates changed as if the iPhone was in portrait mode.

Thats because the window itself doesn't actually change coordinate systems, it applies a transform to its subviews that changes their coordinate system.

> Code and Debugger results are as follows.
> - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
> [[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeLeft];
> return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
> }

Also note that you should not be changing the status bar orientation here. It is sufficient to simply return YES for the orientations that you want (assuming that you've done everything else correctly).
--
David Duncan
Apple DTS Animation and Printing

Joshua Garnham

unread,
Apr 22, 2010, 12:50:48 PM4/22/10
to David Duncan, coco...@lists.apple.com
The reason I have been doing it is because of a problem I have been having with moving a View. Maybe you could help me with that?
The View is supposed to move as my touch moves but the view seems to flicker between to places, as you can see here.
And this is the code I have been using.
--
Joshua Garnham


________________________________
From: David Duncan <david....@apple.com>
To: Joshua Garnham <joshua....@yahoo.co.uk>
Cc: coco...@lists.apple.com
Sent: Thu, 22 April, 2010 17:12:08
Subject: Re: App is in Landscape Mode, but main UIWindow still thinks it’s portrait.
Reply all
Reply to author
Forward
0 new messages