Re: pls explain rotated iPhone coordinates to me
Re: pls explain rotated iPhone coordinates to me
- Subject: Re: pls explain rotated iPhone coordinates to me
- From: Luke the Hiesterman <email@hidden>
- Date: Tue, 15 Dec 2009 07:00:50 -0800
First of all, it's important for you to mention where this code gets
called. Without that, we can't know the whole story, but I'll grant
some notes.
On Dec 14, 2009, at 6:46 PM, Matt Neuburg wrote:
I am not grasping how coordinates work in a rotated iPhone app, and
I'm
hoping someone will explain them.
My goal is a scroll view consisting of two equal "pages" side by
side with
the iPhone sideways (landscape). I have accomplished this, but I don't
understand how I did it; I used pure trial and error, and what works
makes
no sense to me. Here's what I did.
The scroll view occupies the entire window (except for the status
bar, of
course). It has a view controller implemented so as to permit the
autorotation, and the plist tells us to start up in landscape mode.
And we
do. So far so good.
Now I populate the scroll view. I want its content to be double-
wide, but I
have to widen its *height* (svc is the scroll view's controller):
CGRect f = svc.view.frame;
This is weird. You use this rect both to apply back to svc.view.frame
later (which isn't necessary) and you use it for positioning subviews.
Subviews should be positioned within the superview's bounds, not frame.
CGSize sz = CGSizeMake(f.size.height * 2.0, f.size.width); // swap!
Ok, you're not doubling the height. You're making a size whose width
is twice the height of your view....
((UIScrollView*)svc.view).contentSize = sz;
Now I place the first page content:
CardController* cc =
[[CardController alloc] initWithCard: [data objectAtIndex: 0]];
svc.view.frame = f; // don't swap!!
Weird. You never changed f, and you're assigning it back to
svn.view.frame from whence it came. Why is this line here?
[svc.view addSubview:cc.view];
You never applied any frame to cc.view and now you're adding it?
Now I place the second page content:
f.origin.x += f.size.height; // ??? height and width are swapped...
// but x and y are not swapped?????
You're placing the origin at the midway point of the contentView,
because you previously specified that the content width be
f.size.height * 2.0
CardController* cc2 =
[[CardController alloc] initWithCard: [data objectAtIndex: 1]];
cc2.view.frame = f;
Again, should be using a rect based on the bounds, not the frame.
[svc.view addSubview: cc2.view];
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden