【问题标题】:How to position your custom UIView control derived from UITextField如何定位从 UITextField 派生的自定义 UIView 控件
【发布时间】:2011-01-04 06:15:54
【问题描述】:

我扩展了UITextField,以便可以使用我的自定义myInputView。但我无法将myInputView 定位到所需位置。不管我如何设置myInputView 的CGRect 框架,它都会将高度定位在屏幕底部。

查看截图:

正如您在图片中看到的,反转的数字键盘是我的自定义 inputView,但我希望能够将其定位在屏幕中间。

MyTextField.h

@interface MyTextField : UITextField {
    UIView *myInputView;
}
@property (nonatomic, retain) IBOutlet UIView *myInputView;
@end

MyTextField.m

@implementation MyTextField
@synthesize myInputView;

- (UIView *)inputView {
    NSLog(@"Return inputView");

    CGRect frame = CGRectMake(0, 200, 320, 215);
    [myInputView setFrame:frame]; 

    return myInputView;
}

- (void)dealloc {
    [super dealloc];
    [myInputView release];
}
@end

【问题讨论】:

  • 显然,如果您在 TextField 成为第一响应者时将自定义 inputView 分配给自定义 UITextField,它将定位在与使用默认 inputView 相同的高度。

标签: iphone objective-c ios uitextfield position


【解决方案1】:

您可能需要考虑不根据输入视图来实现此功能。设置输入视图让系统像对待键盘一样对待它。您无需设置框架,只需设置高度。我建议去掉UITextField,并用UILabel 替换它,并在上面加上UIButton。将您的自定义输入视图添加到主视图,并将其放置在屏幕外。按下按钮时,将您的自定义输入视图动画化回到屏幕上。当用户进行输入时,只需更新标签。根本不用担心急救人员或UITextField.inputView

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-17
    • 1970-01-01
    • 2011-04-04
    • 1970-01-01
    • 2012-02-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多