簡體   English   中英

在iOS 7中,焦點欄的動畫制作速度比鍵盤快

[英]Focus bar is animating faster than keyboard in iOS 7

我正在鍵盤上方實現自定義焦點欄。 焦點欄上有一些小部件,可將光標與完成按鈕一起來回移動。

現在,在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,我們還需要考慮KeyboardAnimationCurve。 使用以下修改的代碼,我可以正常工作。

- (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 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM