2
我目前有關於動畫的iOS開發的問題。我正在使用下面的代碼來製作一個「幻燈片動畫」,用於在一個gesturerecognizer觸發後切換標籤欄項目。動畫UITabBarController導航
-(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。 是否有這個原因可以發生在標籤欄的「更多」部分,以及對此有什麼可能的解決方案?