Changing the frame of an inputAccessoryView in iOS 8

后端 未结 9 2121
遇见更好的自我
遇见更好的自我 2020-12-13 02:42

Long time lurker - first time poster!

I am having an issue while recreating a bar with a UITextView like WhatsApp does it.

I am using a custom <

9条回答
  •  自闭症患者
    2020-12-13 02:55

    The issue is that in iOS 8, an NSLayoutConstraint that sets the inputAccessoryView's height equal to its initial frame height is installed automatically. In order to fix the layout problem, you need to update that constraint to the desired height and then instruct your inputAccessoryView to lay itself out.

    - (void)changeInputAccessoryView:(UIView *)inputAccessoryView toHeight:(CGFloat)height {
        for (NSLayoutConstraint *constraint in [inputAccessoryView constraints]) {
            if (constraint.firstAttribute == NSLayoutAttributeHeight) {
                constraint.constant = height;
                [inputAccessoryView layoutIfNeeded];
                break;
            }
        }
    }
    

提交回复
热议问题