views:

1295

answers:

2

For the life of me I can't figure out how I'm supposed to set the UITextField to display the text vertically (landscape mode) instead of horizontally (portrait mode). The keyboard shows up properly, but when the keys are pressed the text is entered in the wrong orientation.

Here is the screenshot for the window

And here is the code for the UIViewController

#import "HighScoreViewController.h"

@implementation HighScoreViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
     // Initialization code
    }
    return self;
}


 //Implement loadView if you want to create a view hierarchy programmatically
- (void)loadView {

    UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
    contentView.backgroundColor = [UIColor whiteColor];
    contentView.autoresizesSubviews = YES;
    contentView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); 
    self.view = contentView;
    [contentView release];

    self.view.backgroundColor = [UIColor blackColor];

    CGRect frame = CGRectMake(180.0, 7, 27.0, 120);
    UITextField * txt = [[UITextField alloc] initWithFrame:frame];

    txt.borderStyle = UITextBorderStyleBezel;
    txt.textColor = [UIColor blackColor];
    txt.font = [UIFont systemFontOfSize:17.0];
    txt.placeholder = @"<enter name>";
    txt.backgroundColor = [UIColor whiteColor];
    txt.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support
    //txt.delegate = self;
    txt.keyboardType = UIKeyboardTypeDefault; // use the default type input method (entire keyboard)
    txt.returnKeyType = UIReturnKeyDone;

    txt.clearButtonMode = UITextFieldViewModeWhileEditing; // has a clear 'x' button to the right

    txt.text = @"test";

    [self.view addSubview:txt];
    [txt release];
}


- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    return (interfaceOrientation == UIDeviceOrientationLandscapeRight);
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
    // Release anything that's not essential, such as cached data
}


- (void)dealloc {
    [super dealloc];
}


@end
A: 

iPhone OS handles the orientation changes by applying a transform to the view. Are you applying your own transforms that might interfere?

Kristopher Johnson
I guess I should have posted as a comment, yes we manually set the orientation when the app loads via [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];When I comment this out, it doesn't fix the problem, and the keyboard is now in portrait view.
A: 

We manually set the status bar orientation via setStatusBarOrientation when the app starts up.

-jeremy