横向的UITextField

时间:2008-12-16 20:14:17

标签: iphone objective-c cocoa-touch

对于我的生活,我无法弄清楚我应该如何设置UITextField以垂直显示文本(横向模式)而不是横向(纵向模式)。键盘正确显示,但按下键时,文本输入方向错误。

以下是window

的屏幕截图

这是视图控制器的代码

#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

2 个答案:

答案 0 :(得分:1)

iPhone OS通过对视图应用变换来处理方向更改。您是否正在应用可能会干扰的变换?

答案 1 :(得分:0)

我们在应用启动时通过setStatusBarOrientation手动设置状态栏方向。

-jeremy