简体   繁体   English

UITextField inputView未在iPhone 6中显示

[英]UITextField inputView not showing in iPhone 6

I have a weird bug which only happens in iPhone 6 simulator in Xcode 6. I have a generic component which extends UITextField and shows a pickerView as inputView at the bottom of screen. 我有一个奇怪的错误,只发生在Xcode 6的iPhone 6模拟器中。我有一个通用组件,它扩展了UITextField并在屏幕底部显示了一个pickerView作为inputView。

If I use iPhone5 or iPhone5s to test my application, it's working as expected: inputView and inputAccessoryView is displaying correctly. 如果我使用iPhone5或iPhone5s来测试我的应用程序,它正在按预期工作:inputView和inputAccessoryView正确显示。 But if I switch to iPhone 6 or Plus simulator, only inputAccessoryView is shown at bottom of screen, inputView is not showing. 但是如果我切换到iPhone 6或Plus模拟器,屏幕底部只显示inputAccessoryView,则不显示inputView。

Here is my code: 这是我的代码:

@interface DropDownTextField : UITextField

@property (strong,nonatomic) UIPickerView* pickerView;
@property (strong,nonatomic) UIToolbar *toolBar;
@property CGFloat originalFontSize;

@property (nonatomic) id<UIPickerViewDelegate> pickerDelegate;
@property (nonatomic) id<UIPickerViewDataSource> pickerDataSource;

- (CGFloat)requiredFontSize;
- (void)setDropdownMode:(BOOL)enabled;

@end

@implementation DropDownTextField

-(id)initWithCoder:(NSCoder *)aDecoder {
    if(self = [super initWithCoder:aDecoder]) {
        self.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
        self.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;

        [self setFont:[UIFont mediumRegular]];
        _originalFontSize = self.font.pointSize;

        self.layer.borderWidth = 1.0f;

        CGRect frame = [self frame];

        // rightview dropdown arrow
        UIImageView *dropDownImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, (frame.size.height-8)/2, 14.0f, 8.0f)];
        UIImage *dropDownImage = [UIImage imageNamed:@"DisclosureDown"];
        [dropDownImageView setImage:dropDownImage];
        dropDownImageView.contentMode = UIViewContentModeScaleAspectFit;
        UIView *dropDownView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 25.0f, frame.size.height)];
        [dropDownView addSubview:dropDownImageView];

        self.rightView = dropDownView;
        self.rightViewMode = UITextFieldViewModeAlways;
        [self.rightView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(becomeFirstResponder)]];

        // picker view
        _pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0,0,SCREEN_WIDTH,216)];
        _pickerView.showsSelectionIndicator = YES;
        [_pickerView setBackgroundColor:[UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1.0f]];
        self.inputView = _pickerView;

        // picker view toolbar
        _toolBar= [[UIToolbar alloc] initWithFrame:CGRectMake(0,0,SCREEN_WIDTH,44)];
        [_toolBar setBackgroundColor:[UIColor colorWithRed:229/255.0 green:229/255.0 blue:229/255.0 alpha:1.0f]];
        [_toolBar setBarStyle:UIBarStyleBlackTranslucent];

        // to align button to the right
        UIBarButtonItem *flex = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];

        UIBarButtonItem *barButtonDone = [[UIBarButtonItem alloc] init];
        [barButtonDone setTarget:self];
        [barButtonDone setAction:@selector(changeSelectionFromLabel:)];
        [barButtonDone setTitle:NSLocalizedString(@"ok", @"")];
        [barButtonDone setTintColor:[UIColor colorWithRed:229/255.0 green:229/255.0 blue:229/255.0 alpha:1.0f]];
        [barButtonDone setStyle:UIBarButtonItemStylePlain];
        [barButtonDone setTitleTextAttributes:[UIFont pickerTitleTextAttributes] forState:UIControlStateNormal];

        UIBarButtonItem *barButtonCancel = [[UIBarButtonItem alloc] init];
        [barButtonCancel setTarget:self];
        [barButtonCancel setAction:@selector(dismissPickerView:)];
        [barButtonCancel setTitle:NSLocalizedString(@"cancel", @"")];
        [barButtonCancel setTintColor:[UIColor colorWithRed:229/255.0 green:229/255.0 blue:229/255.0 alpha:1.0f]];
        [barButtonCancel setStyle:UIBarButtonItemStylePlain];
        [barButtonCancel setTitleTextAttributes:[UIFont pickerTitleTextAttributes] forState:UIControlStateNormal];

        self.toolBar.items = [[NSArray alloc] initWithObjects:barButtonCancel,flex,barButtonDone,nil];
        self.inputAccessoryView = _toolBar;


    }
    return self;
}

Does anybody come across such a problem? 有人遇到过这样的问题吗? Any ideas to resolve? 有什么想法要解决?

PS: I've already tried clearing build directory, clean/rebuild project, stop/restart simulator and xcode approaches. PS:我已经尝试清除构建目录,清理/重建项目,停止/重启模拟器和xcode方法。 Not working. 不工作。

尝试取消选中模拟器 - >硬件 - >键盘 - >连接硬件键盘

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM