iOS同步动画没有完成块



我有一个带有标准工具栏的视频播放器。工具栏通过向下滑动手势而消失。我还有一个视图(实际上是一个面板),它可以直接出现在工具栏上方,也可以通过向下滑动手势来消除。当面板和工具栏都打开时,一个向下滑动的手势将关闭面板,第二个手势将关闭工具栏。问题是,当滑动手势快速背靠背发生时(在面板动画完成之前),工具栏动画会抖动。

- (void)handleSwipe:(UISwipeGestureRecognizer *)gestureRecognizer
{
    UISwipeGestureRecognizerDirection direction = [gestureRecognizer direction];
    if (direction == UISwipeGestureRecognizerDirectionDown) {
        if (![toolbar isHidden]) {
            // Only dismiss the bottom panel if it is open
            if (_selectedSegmentIndex != UISegmentedControlNoSegment) {
                _selectedSegmentIndex = UISegmentedControlNoSegment;
                [bottomPanelView dismissPanel];
            } else {
                CGRect tempRect = CGRectMake(0, self.view.frame.size.height, toolbar.frame.size.width, toolbar.frame.size.height);
                [UIView animateWithDuration:0.25f
                                 animations:^{
                                    // Move the toolbar off the screen.
                                    toolbar.frame = tempRect;
                                 }
                                 completion:^(BOOL finished) {
                                     [toolbar setHidden:YES];
                                 }];
            }
        }
    }
}

[bottomPanelView dismissPanel]在一个单独的类中,不知道调用它的类。它有以下动画。。。

[UIView animateWithDuration:self.panelAnimationDuration
                      delay:0.0
                    options:UIViewAnimationOptionCurveLinear
                 animations:^{
                     // slideOutLocation is off the screen 
                     self.view.frame = slideOutLocation;
                 }
                 completion:^(BOOL finished) {
                     [self.view removeFromSuperview];
                     [self removeFromParentViewController];
                     self.panelActive = NO;
                 }];

因此,基本上,当解除工具栏的动画开始时,解除面板动画仍在运行。在模拟器中以慢动作执行双滑动时,第一个动画看起来很好,但工具栏动画会抖动。

我知道如何在完成块中嵌套动画,但在这里无法做到这一点,因为并不总是需要同时关闭面板和工具栏。此外,dissePanel代码在其他地方处理,不在工具栏的控制范围内。

有没有一种方法可以允许多个动画块同时运行而不放置完成块?如果需要澄清,请告诉我!谢谢

我想知道这个问题是否与自动布局有关(在自动布局打开时设置帧会导致问题)。我尝试了一个简单的测试,通过设置视图和屏幕底部工具栏的约束常数来设置它们的动画,动画看起来很好。我根据各自的底部约束(称为viewBottomCon和toolBarBottomCon)制作了IBOutlets。

- (void)viewDidLoad {
    [super viewDidLoad];
    self.isFirstSwipe = YES;
}
-(IBAction)downSwipe:(UISwipeGestureRecognizer *)sender {
    if (self.isFirstSwipe) {
        self.viewBottomCon.constant = -52;
        self.isFirstSwipe = NO;
        [UIView animateWithDuration:5 animations:^{
            [self.view layoutIfNeeded];
        } completion:nil];
    }else if (!self.isFirstSwipe) {
        self.toolBarBottomCon.constant = -44;
        [UIView animateWithDuration:3 animations:^{
            [self.view layoutIfNeeded];
        } completion:nil];
    }
}

这是一个比你的设置更简单的设置,但我认为它也应该适用于你的情况。

最新更新