代码之家  ›  专栏  ›  技术社区  ›  Jeremy

面向景观的uitextfield

  •  0
  • Jeremy  · 技术社区  · 16 年前

    为了我的生命,我不知道我该如何设定 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 回复  |  直到 12 年前
        1
  •  1
  •   Kristopher Johnson    16 年前

    iphone os通过对视图应用转换来处理方向更改。你是否正在应用你自己的可能会干扰的转换?

        2
  •  0
  •   Jeremy    16 年前

    当应用程序启动时,我们通过setStatusBarOrientation手动设置状态栏方向。

    -杰瑞米