UITextField in landscape orientation

In life, I can't figure out how I should set UITextField

to display text vertically (landscape mode) instead of horizontal (portrait mode). The keyboard displays correctly, but when you press the keys, the text is entered in the wrong orientation.

Here is a screenshot for the window

And here is the code for the view controller

#import "HighScoreViewController.h"

@implementation HighScoreViewController

 //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);
}

@end

      

0


source to share


2 answers


iPhone OS handles orientation changes by applying a transform to the view. Are you applying your own transformations that might get in the way?



+1


source


We manually set the orientation of the status bar using setStatusBarOrientation when the application starts.



-jeremy

0


source







All Articles