Pergunta

Estou implementando uma barra de foco personalizada na parte superior do meu teclado.A barra de foco possui widgets para mover o cursor para frente e para trás junto com um botão Concluído.

Agora, com o iOS 7, vejo que a barra de foco se move mais rápido que o teclado.Por causa disso, por um segundo, vejo a tela atrás da barra de foco antes de ela ficar no topo do teclado.Isso está funcionando bem no iOS 6.

Abaixo está o que estou fazendo:

- (void)keyboardWillShow:(NSNotification *)iNotification {
    self.dismissForm = NO;
    self.shouldScrollCell = YES;
    CGFloat aKeyboardAnimationDuration = [[iNotification userInfo][UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    CGRect aKeyboardFrame = [[iNotification userInfo][UIKeyboardFrameEndUserInfoKey] CGRectValue];
    CGRect adjustedKeyboardFrame = [self.view convertRect:aKeyboardFrame fromView:nil];
    CGFloat adjustedHeight;
    adjustedHeight = aKeyboardFrame.size.height + self.focusControlBar.frame.size.height;
    [self.focusControlBar viewForFocusControlWillShowWithEndFrame:adjustedKeyboardFrame andAnimationDuration:aKeyboardAnimationDuration];

    [UIView animateWithDuration:0.3 animations:^() {
        [self.tableView setContentInset:UIEdgeInsetsMake(kScreenOrigin, kScreenOrigin, adjustedHeight, 0.0f)];
        [self.tableView setScrollIndicatorInsets:UIEdgeInsetsMake(kScreenOrigin, kScreenOrigin, adjustedHeight, 0.0f)];
    }];
}

Este é o meu código de animação da barra de foco:

- (void)viewForFocusControlWillShowWithEndFrame:(CGRect)iFrame andAnimationDuration:(CGFloat)iDuration {
    BOOL aShouldAppear = YES;   

    if (self.delegate && [self.delegate respondsToSelector:@selector(focusControlBarShouldAppear:)]) {
        aShouldAppear = [self.delegate focusControlBarShouldAppear:self];
    }

    if (aShouldAppear) {
        if (self.delegate && [self.delegate respondsToSelector:@selector(focusControlBarWillAppear:)]) {
            [self.delegate focusControlBarWillAppear:self];
        }
        CGRect aBarFrame = self.frame;
        UIInterfaceOrientation anInterfaceOrientation = [UIApplication sharedApplication].statusBarOrientation;
        aBarFrame.size.height = [self heightForOrientation:anInterfaceOrientation];
        self.frame = aBarFrame;
        aBarFrame.origin.y = self.superview.bounds.size.height - iFrame.size.height - aBarFrame.size.height;


        [UIView animateWithDuration:iDuration animations:^(void) {
            self.frame = aBarFrame;
        } completion:^(BOOL iFinished) {
            if (self.delegate && [self.delegate respondsToSelector:@selector(focusControlBarDidAppear:)]) {
                [self.delegate focusControlBarDidAppear:self];
            }
        }];
    }
}
Foi útil?

Solução

Acabei de saber que com o iOS 7 também precisamos levar em consideração o KeyboardAnimationCurve.Com o código modificado abaixo, funcionou.

- (void)keyboardWillShow:(NSNotification *)iNotification {
    self.dismissForm = NO;
    self.shouldScrollCell = YES;

    NSDictionary *aNotificationInfo = [iNotification userInfo];
    CGFloat aKeyboardAnimationDuration = [aNotificationInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    UIViewAnimationCurve aKeyboardAnimationCurve = [aNotificationInfo[UIKeyboardAnimationCurveUserInfoKey] intValue];
    CGRect aKeyboardFrame = [aNotificationInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    CGRect adjustedKeyboardFrame = [self.view convertRect:aKeyboardFrame fromView:nil];
    CGFloat adjustedHeight;
    adjustedHeight = aKeyboardFrame.size.height + self.focusControlBar.frame.size.height;

    [self.focusControlBar viewForFocusControlWillShowWithEndFrame:adjustedKeyboardFrame animationCurve:aKeyboardAnimationCurve andAnimationDuration:aKeyboardAnimationDuration];

    [UIView animateWithDuration:0.3 animations:^() {
        [self.tableView setContentInset:UIEdgeInsetsMake(kScreenOrigin, kScreenOrigin, adjustedHeight, 0.0f)];
        [self.tableView setScrollIndicatorInsets:UIEdgeInsetsMake(kScreenOrigin, kScreenOrigin, adjustedHeight, 0.0f)];
    }];
}

- (void)viewForFocusControlWillShowWithEndFrame:(CGRect)iFrame animationCurve:(UIViewAnimationCurve)iAnimationCurve andAnimationDuration:(CGFloat)iDuration {
    BOOL aShouldAppear = YES;   

    if (self.delegate && [self.delegate respondsToSelector:@selector(focusControlBarShouldAppear:)]) {
        aShouldAppear = [self.delegate focusControlBarShouldAppear:self];
    }

    if (aShouldAppear) {
        if (self.delegate && [self.delegate respondsToSelector:@selector(focusControlBarWillAppear:)]) {
            [self.delegate focusControlBarWillAppear:self];
        }

        CGRect aBarFrame = self.frame;
        UIInterfaceOrientation anInterfaceOrientation = [UIApplication sharedApplication].statusBarOrientation;
        aBarFrame.size.height = [self heightForOrientation:anInterfaceOrientation];
        self.frame = aBarFrame;
        aBarFrame.origin.y = self.superview.bounds.size.height - iFrame.size.height - aBarFrame.size.height;

        [UIView animateWithDuration:iDuration delay:0.0 options:(iAnimationCurve << 16) animations:^{
            self.frame = aBarFrame;
        } completion:^(BOOL finished) {
            if (self.delegate && [self.delegate respondsToSelector:@selector(focusControlBarDidAppear:)]) {
                [self.delegate focusControlBarDidAppear:self];
            }
        }];
    }
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top