【发布时间】:2013-12-05 23:53:08
【问题描述】:
我有一个带有标准工具栏的视频播放器。向下滑动手势会关闭工具栏。我还有一个视图(实际上是一个面板),它可以直接显示在工具栏上方,并且也可以通过向下滑动手势来消除。当面板和工具栏都打开时,一个向下滑动手势应该关闭面板,第二个手势将关闭工具栏。问题是当滑动手势快速连续发生时(在面板动画完成之前),工具栏动画会抖动。
- (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;
}];
所以基本上,当关闭工具栏的动画开始时,dismissPanel 动画仍在运行。在模拟器中以慢动作执行双击时,第一个动画看起来不错,但工具栏动画很抖动。
我知道如何在完成块中嵌套动画,但是这里不能这样做,因为关闭面板和工具栏并不总是想要的。此外,dismissPanel 代码在其他地方处理,并且不受工具栏的控制。
有没有办法让多个动画块同时运行而不放置完成块?让我知道是否需要任何澄清!谢谢!
【问题讨论】:
-
我认为当你第二次滑动时你应该停止第一个动画。在这里查看答案:stackoverflow.com/questions/554997/cancel-a-uiview-animation。然后你可以启动另一个动画让它返回,它现在在哪里并不重要。
-
我已经尝试使用
removeAllAnimations作为该帖子中提到的用户之一删除动画。即使我在面板视图上运行removeAllAnimations,它似乎也阻止了我的工具栏动画,因为工具栏在第二次滑动时消失了,而不是从屏幕上滑下来。
标签: ios objective-c cocoa core-animation objective-c-blocks