显示键盘时,导航栏不可见

时间:2016-12-29 23:10:24

标签: ios objective-c navbar

textView显示或隐藏键盘时,我使用波纹管代码向上或向下移动屏幕,通过这种方式,我可以看到最后一个字段在它聚焦时。< / p>

- (void)textViewDidBeginEditing:(UITextView *)textField
{
    [self animateTextView: textField up: YES];
}


- (void)textViewDidEndEditing:(UITextView *)textField
{
    [self animateTextView: textField up: NO];
}

- (void) animateTextView: (UITextView*) textField up: (BOOL) up
{
    const int movementDistance = 130; // tweak as needed
    const float movementDuration = 0.2f; // tweak as needed

    int movement = (up ? -movementDistance : movementDistance);

    [UIView beginAnimations: @"anim" context: nil];
    [UIView setAnimationBeginsFromCurrentState: YES];
    [UIView setAnimationDuration: movementDuration];
    self.view.frame = CGRectOffset(self.view.frame, 0, movement);
    [UIView commitAnimations];
}

但问题是,当屏幕向上移动时,navBar它也会移动,是否有办法移动除navBar以外的所有内容或将navBar保留在其中{&}} #39;使用[self animateTextView: textField up: YES];后的位置?

1 个答案:

答案 0 :(得分:1)

这是因为您在主视图中有自定义NavigationBar。 在故事板中的NavBar下面创建另一个UIView,然后将textField和其他UI对象放在这个新视图中。 保持这一点这是心灵导航栏不应该在键盘出现时向上推动的同一个UIView对象的旁边。 因此,创建一个新创建的UIView对象的出口,而不是移动viewController的主视图,只需模式新建这样的视图。

[UIView animateWithDuration:0.2 animations:^{
    //Just Replace Your Animation Code with This and see the difference.
    self.containerViewOfOtherObjects.frame = CGRectOffset(self.containerViewOfOtherObjects.frame, 0, movement);
}];
相关问题