我在键盘顶部实施自定义焦点栏。Focus栏有小部件,用于将光标向后和向前移动,以及完成按钮。

现在,使用iOS 7,我看到焦点栏比键盘更快地移动。因为这一点,我看到焦点栏后面的屏幕坐在键盘上。这在iOS 6中正常工作。

以下是我正在做的事情:

- (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)];
    }];
}
.

这是我的焦点栏动画代码:

- (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];
            }
        }];
    }
}
.

有帮助吗?

解决方案

我刚才与iOS 7一起,我们需要将键盘映射到帐户中。使用以下修改代码,我已经工作了。

- (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];
            }
        }];
    }
}
.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top