Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/94.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Can';t切换到数字键盘iOS_Ios_Uikeyboard - Fatal编程技术网

Can';t切换到数字键盘iOS

Can';t切换到数字键盘iOS,ios,uikeyboard,Ios,Uikeyboard,我的应用程序不允许用户将键盘切换到数字/字符键盘 我的UI检查器中没有任何内容显示在屏幕底部 我真的很困惑到底是什么导致了这个问题。无论它是什么,都会阻止数字/符号切换器、键盘语言(或表情符号)选择器和语音到文本按钮。同一行上的空格键和回车键继续正常工作 受影响的UITextField是子类的,键盘在包含它们的其他5个视图上按预期工作,但下面是它们的代码: JCTextField.h #import <UIKit/UIKit.h> IB_DESIGNABLE @interface

我的应用程序不允许用户将键盘切换到数字/字符键盘

我的UI检查器中没有任何内容显示在屏幕底部

我真的很困惑到底是什么导致了这个问题。无论它是什么,都会阻止数字/符号切换器、键盘语言(或表情符号)选择器和语音到文本按钮。同一行上的空格键和回车键继续正常工作

受影响的UITextField是子类的,键盘在包含它们的其他5个视图上按预期工作,但下面是它们的代码:

JCTextField.h

#import <UIKit/UIKit.h>

IB_DESIGNABLE
@interface JCTextField : UITextField

@property (nonatomic, retain) IBInspectable UIColor *underlineColor;
@property (nonatomic) IBInspectable CGFloat underlineWidth;
@property (nonatomic, retain) IBInspectable UIImage *sideImage;
@property (nonatomic) IBInspectable CGFloat internalOffset;
@property (nonatomic) IBInspectable CGFloat borderOffset;

@end

明显的问题是:你的文本字段的
键盘类型
或任何其他奇怪的东西有什么特别之处吗?@dasblinkenlight它在Objective-C中,完全原生,全部在Xcode中完成。@matt我使用的是子类文本字段,但我在所有地方都使用相同的子类文本字段(处理UI)键盘在其他5个视图上也能正常工作。不过,文本字段是一个子类这一事实可能很重要。您还没有显示子类代码,因此这只能是猜测;只有你可以考虑这个问题(除非你想分享代码)。好吧,你的代码很疯狂,我想你也知道。不支持为文本字段重写
drawRect:
,您的重写有点疯狂,因为您甚至不进行绘图,而只是添加子层和其他内容-而且由于可以大量调用
drawRect:
,因此您将得到大量子层和其他内容。在某种程度上,您似乎只是误用了
drawRect:
来初始化文本字段的物理配置。为什么这样做?为什么不在适当的地方初始化一次呢?我并不是说这是你麻烦的原因,但我强烈建议你先解决这个问题。
#import "JCTextField.h"

@implementation JCTextField

- (id)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if(self != nil) {
        self.underlineColor = [UIColor blackColor];
        self.underlineWidth = 1;
        self.internalOffset = 0;
        self.borderOffset = 0;
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    CALayer *border = [CALayer layer];
    border.borderColor = _underlineColor.CGColor;
    border.frame = CGRectMake(_borderOffset, self.frame.size.height - _underlineWidth, self.frame.size.width - (_borderOffset * 2), self.frame.size.height);
    border.borderWidth = _underlineWidth;
    [self.layer addSublayer:border];
    self.layer.masksToBounds = YES;


    [self setValue:[UIColor lightTextColor] forKeyPath:@"_placeholderLabel.textColor"];
    [self setTextColor:[UIColor whiteColor]];
    [self setFont:[UIFont fontWithName:@"Montserrat-Regular" size:16.0]];


    if (self.sideImage) {
        UIImageView *sideImageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.frame.size.width - 30, 0, 30, 30)];
        sideImageView.contentMode = UIViewContentModeCenter;
        sideImageView.image = self.sideImage;
        [self addSubview:sideImageView];
    }

    [self setTintColor:[UIColor whiteColor]];

    [self setValue:[UIColor lightGrayColor] forKeyPath:@"_placeholderLabel.textColor"];

}

- (CGRect)textRectForBounds:(CGRect)bounds {
    if (self.sideImage) {
        UIEdgeInsets insets = UIEdgeInsetsMake(0, _internalOffset, 0, 18);
        return [super textRectForBounds:UIEdgeInsetsInsetRect(bounds, insets)];
    }
    UIEdgeInsets insets = UIEdgeInsetsMake(0, _internalOffset, 0, 0);
    return [super textRectForBounds:UIEdgeInsetsInsetRect(bounds, insets)];
}

- (CGRect)editingRectForBounds:(CGRect)bounds {
    if (self.sideImage) {
        UIEdgeInsets insets = UIEdgeInsetsMake(0, _internalOffset, 0, 18);
        return [super textRectForBounds:UIEdgeInsetsInsetRect(bounds, insets)];
    }
    UIEdgeInsets insets = UIEdgeInsetsMake(0, _internalOffset, 0, 0);
    return [super textRectForBounds:UIEdgeInsetsInsetRect(bounds, insets)];
}

@end