UITextField text jumps iOS 9

前端 未结 5 1452
名媛妹妹
名媛妹妹 2020-12-19 00:35

Link for previous question: UITextField text jumps

Briefly: I have ViewController with 2 UITextField elements. When loginField is firstResp

5条回答
  •  旧时难觅i
    2020-12-19 01:03

    I've faced same issue, when I was trying to change first responder. There is a better solution for this issue. Just implement UITextField subclass and used in places, where your text field can be animated (keyboard, first respond switching and so on).

    @interface UITextFieldFixed : UITextField
    
    @end
    
    @implementation UITextFieldFixed
    
    - (BOOL)resignFirstResponder
    {
        BOOL result = [super resignFirstResponder];
        [self setNeedsLayout];
        [self layoutIfNeeded];
        return result;
    }
    
    @end
    

    More info about issue: https://github.com/foundry/UITextFieldBug

    Copy and paste for Swift3...

    class UITextFieldFixed: UITextField {
        override func resignFirstResponder() -> Bool {
            let r = super.resignFirstResponder()
            self.setNeedsLayout()
            self.layoutIfNeeded()
            return r
        }
    }
    

提交回复
热议问题