UITextField

2017年6月28日
1.文本框不可以编辑

_contentTF.userInteractionEnabled = NO;

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    return NO;
}

2017年6月22日
一.系统键盘挡住输入框解决 (整个内容视图整体上移解决)
1.键盘显示的时候整个显示视图上移,键盘消失的时候还原

@interface HuRegistrerViewController ()
{
    UIButton *_loginBtn;
    CGFloat _oldContentViewYPos;
}
@end
@implementation HuRegistrerViewController
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self addNotifictionListener];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [self removeNotificationListener];
}

- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    _oldContentViewYPos = self.view.frame.origin.y;
}

- (void)addNotifictionListener
{
    [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(keyboardWillShow:) name: UIKeyboardWillShowNotification object: nil];
    [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(keyboardWillHide:) name: UIKeyboardWillHideNotification object: nil];
}

- (void)removeNotificationListener
{
    [kNotificationCenter removeObserver: self];
}

- (void)keyboardWillShow: (NSNotification*)notice
{
    NSValue *frameValue = [notice.userInfo objectForKey: UIKeyboardFrameEndUserInfoKey];
    CGRect frameRect = {0};
    [frameValue getValue: &frameRect];
    
    UIView *contentView = self.view;
    int inputFieldTop = _loginBtn.bottom + _oldContentViewYPos;
    
    if (frameRect.origin.y < inputFieldTop) {
        CGRect viewFrame = contentView.frame;
        viewFrame.origin.y -= inputFieldTop - frameRect.origin.y;
        contentView.frame = viewFrame;
    }
}

- (void)keyboardWillHide:(NSNotification*)notice //键盘消失,布局还原
{
    UIView *contentView = self.view;
    
    CGRect viewFrame = contentView.frame;
    viewFrame.origin.y =_oldContentViewYPos;
    contentView.frame = viewFrame;
}
@end

如果您发现本文对你有所帮助,如果您认为其他人也可能受益,请把它分享出去。

你可能感兴趣的:(UITextField)