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
    

したがって、私の UIViewController はself.view.frame.origin.yプッシュ/ポップの間で失われるようです...

IB では、両方のビュー (detailView と PushView) のすべてのサイズが「推定」に設定されています。次のオプションも、両方のビューで同じようにチェックされます。

  • スクロール ビュー インセットの調整
  • プッシュ時にボトムバーを非表示
  • エッジを延長: 上部バーの下
  • " " : ボトムバーの下
  • " " : 不透明バーの下

では、私のビューに何が起こっているのでしょうか? ご協力いただきありがとうございます。

4

1 に答える 1

0

いつものように、オブザーバーがどのように追加されるかについてです:viewDidLoadメソッドではなく、viewWillAppear. これで修正されました。

于 2013-11-10T15:05:01.410 に答える