UIEdgeInsets не работает точно так же, как ожидалось

Я добавил scrollView в контроллере представления и зарегистрировал показ клавиатуры и скрытые уведомления

- (void)viewDidLoad {
    [super viewDidLoad];

    self.navigationController.navigationBar.translucent = NO;

    [self registerForKeyboardNotifications];

    // add UITapGestureRecognizer
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
                                   initWithTarget:self
                                   action:@selector(dismissKeyboard)];
    [scrollView addGestureRecognizer:tap];
    scrollView.delegate = self;

    [self setupAView];
}

- (void)setupAView {
  // setting up aView...

  scrollView.contentSize = CGSizeMake(self.view.frame.size.width, aView.frame.size.height);

-(void)dismissKeyboard {
    [aView.aTextView resignFirstResponder];
}

- (void)registerForKeyboardNotifications
{
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWasShown:)
                                                 name:UIKeyboardDidShowNotification object:nil];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillBeHidden:)
                                                 name:UIKeyboardWillHideNotification object:nil];

}

- (void)keyboardWasShown:(NSNotification*)aNotification
{
    UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, aView.frame.size.height, 0.0);
    scrollView.contentInset = contentInsets;
    scrollView.scrollIndicatorInsets = contentInsets;

    CGPoint aPoint = CGPointMake(0, aView.frame.size.height);
    [scrollView setContentOffset:aPoint animated:NO];
}

- (void)keyboardWillBeHidden:(NSNotification*)aNotification
{
    // scrollView insets
    UIEdgeInsets contentInsets = UIEdgeInsetsZero;
    scrollView.contentInset = contentInsets;
    scrollView.scrollIndicatorInsets = contentInsets;
}

это работает нормально, когда я нажимаю aTextView, и aView в scrollView будет перемещаться над видом клавиатуры, но в то же время, если я прокручиваю scrollView, весь вид автоматически будет немного выпадать вниз. Почему действие изменит значение вставки или значение scrollView contentSize?

скроллвью выпадает

0 ответов

Другие вопросы по тегам