0

我有一个带有底部工具栏的 DetailViewController。

这个工具栏有 UIButtons 和 UITextField 对象。

为了让这些 UITextField 在编辑时可见,我使用以下例程:

- (void) returnMainViewToInitialposition:(NSNotification*)aNotification{
    [self scrollViewForKeyboard:aNotification up:NO];
}

- (void) scrollViewForKeyboard:(NSNotification*)aNotification up:(BOOL) up{
    if (_detailItem && ( self.addressTextField.editing || self.urlTextField.editing || self.titleTextField.editing )) {
        NSDictionary* userInfo = [aNotification userInfo];

        // Get animation info from userInfo
        NSTimeInterval animationDuration;
        UIViewAnimationCurve animationCurve;
        CGRect keyboardFrame;
        [[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:&animationCurve];
        [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] getValue:&animationDuration];
        [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] getValue:&keyboardFrame];
        CGFloat _keyboardHeight = ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait || [[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown) ? keyboardFrame.size.height : keyboardFrame.size.width;
        // Animate up or down
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:animationDuration];
        [UIView setAnimationCurve:animationCurve];
        [self.view setFrame:CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y + _keyboardHeight * (up?-1:1), self.view.frame.size.width, self.view.frame.size.height)];
        [UIView commitAnimations];
        NSLog(@"detailView bounds: %.0f, (%.0f + %.0f x %d), %3.0f, %3.0f", self.view.frame.origin.x, self.view.frame.origin.y + _keyboardHeight * (up?-1:1), _keyboardHeight, (up?-1:1), self.view.frame.size.width, self.view.frame.size.height);

    }
}

+ (CGRect) convertRect:(CGRect)rect toView:(UIView *)view {
    UIWindow *window = [view isKindOfClass:[UIWindow class]] ? (UIWindow *) view : [view window];
    return [view convertRect:[window convertRect:rect fromWindow:nil] fromView:nil];
}

它可以工作,直到我将另一个视图推到当前视图之上,然后将其弹出。然后我在编辑它们时看不到我的 UITextField。

这是上面的 NSLog 所说的:

  • 在推动(工作)之前:

    detailView bounds: 0, (-704 + 352 x -1), 703, 768
    
  • 弹出后(不):

    detailView bounds: 0, (352 + 352 x 1), 703, 768
    

所以看起来我的 UIViewControllerself.view.frame.origin.y在推送/弹出之间失去了它......

在 IB 中,两个视图(detailView 和 pushView)的所有大小都设置为“推断”。两个视图的以下选项也同样检查:

  • 调整滚动视图插图
  • 按下时隐藏底栏
  • 延伸边缘:在顶栏下方
  • " " : 在底栏下
  • " " : 在不透明条下

那么,我的观点发生了什么变化?谢谢你的帮助。

4

1 回答 1

0

与往常一样,它是关于如何添加观察者的:它们不应该被添加到viewDidLoad方法中,而应该添加到viewWillAppear. 现在已经修好了。

于 2013-11-10T15:05:01.410 回答