views:

507

answers:

1

I have a iPhone app with a main view that is 480 x 510. I'm a bit confused as to how the coordinate system changes when I go from portrait to landscapeRight.

Initially, I had a 480x480 content area, and wanted to add a button on the side to bring up a menu. However, the only way I could find to have the writing run down the length of the left side of the app was to change the orientation of the whole app to landscape right.

Now, with the orientation in Landscape, the scrollview is starting at the top left, when I really want it to start at the original orientation point (from when it was in portrait mode), which would be bottom left. But I can't figure out how to change the original starting point of the scrollview. I tried contentOffset, but it doesn't seem to be working.

Another way of going about this (that I might end up doing) is forget having a title on the button, and just create a graphic for the button that has text vertically oriented.

if (self = [super initWithCoder:coder]) {
 // Size of the scrollview
 self.contentSize = CGSizeMake(480, 510);
 [self setContentOffset:CGPointMake (0, -160)];
 self.showsHorizontalScrollIndicator = YES;
 self.showsVerticalScrollIndicator = YES;
 self.alwaysBounceVertical = NO;
 self.alwaysBounceHorizontal = NO;
 self.bounces = YES;
 self.userInteractionEnabled = YES;
 self.musicGridView = [[[MusicGridView alloc] initWithCoder:coder] autorelease];
 // Rectangle where I put the music grid (origin is left aligned, and down 160 pixels to account for landscape view)
 self.musicGridView.frame = CGRectMake(0, 160, 480, 480);
 [self addSubview: musicGridView];

 self.menuButton = [UIButton buttonWithType:UIButtonTypeCustom];
 self.menuButton.frame = CGRectMake(0, 480, 480, 32);
 [menuButton setTitle: @"Tap to get Menu" forState: UIControlStateNormal];
 [menuButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
 [menuButton addTarget:self action:@selector(showMenu) forControlEvents:UIControlEventTouchUpInside];

 [self addSubview: menuButton];
A: 

Andrey Tarantsov has done an awesome rundown of the various quirks of the UIScrollView class, including code for various workarounds to common problems. It might be worthwhile taking a look.

Nathan de Vries