我目前在有关动画的 iOS 开发中遇到问题。我目前正在使用以下代码制作“幻灯片动画”,以便在手势识别器触发后切换标签栏项目。
-(void)slideToTab:(int)controllerIndex
{
if(controllerIndex >= 0 && controllerIndex < [self.tabBarController.viewControllers count])
{
// Get the views.
UIView * fromView = self.tabBarController.selectedViewController.view;
UIView * toView = [[self.tabBarController.viewControllers objectAtIndex:controllerIndex] view];
// Get the size of the view area.
CGRect viewSize = fromView.frame;
BOOL scrollRight = controllerIndex > self.tabBarController.selectedIndex;
// Add the to view to the tab bar view.
[fromView.superview addSubview:toView];
// Position it off screen.
toView.frame = CGRectMake((scrollRight ? 320 : -320), viewSize.origin.y, 320, viewSize.size.height);
[UIView animateWithDuration:0.3
animations: ^{
// Animate the views on and off the screen. This will appear to slide.
fromView.frame =CGRectMake((scrollRight ? -320 : 320), viewSize.origin.y, 320, viewSize.size.height);
toView.frame =CGRectMake(0, viewSize.origin.y, 320, viewSize.size.height);
}
completion:^(BOOL finished) {
if(finished)
{
// Remove the old view from the tabbar view.
[fromView removeFromSuperview];
self.tabBarController.selectedIndex = controllerIndex;
}
}];
}
}
对于选项卡栏上的选项卡栏项目,此代码工作正常,但每当我点击位于选项卡栏“更多”部分的第一个选项卡时,动画停止工作并且完成块中的已完成布尔值返回 false。在标签栏的“更多”部分发生这种情况是否有原因,对此可能的解决方案是什么?