2012-12-31 79 views
0

我正在編寫一個使用UISplitViewController和UISegmentedControl的通用應用程序。 UISegmentedControl中的每個控制器都允許編輯。當段成爲當前段時,似乎必須重新建立控制器的編輯狀態。我的問題是由[vc setEditing:YES animation:NO]產生的奇怪的動畫。有人可以建議我如何避免這種情況?謝謝。在UISegment控件內設置編輯

- (void)segmentChanged:(UISegmentedControl *)sender 
{ 
    UIViewController *vc = [self viewControllerForSegmentIndex:sender.selectedSegmentIndex]; 
    [self addChildViewController:vc]; 

    [self transitionFromViewController:self.currentViewController toViewController:vc duration:0.3 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{ 
     [self.currentViewController.view removeFromSuperview]; 
     vc.view.frame = self.view.bounds; 
     [self.view addSubview:vc.view]; 
     [vc setEditing:YES animated:NO]; 
    } completion:^(BOOL finished) { 
     [vc didMoveToParentViewController:self]; 
     [self.currentViewController removeFromParentViewController]; 
     self.currentViewController = vc; 
    }]; 

回答

0

爲了避免不適當的動畫,我完成用於與setEditing和viewWillAppear中控制器的顯示在製備製劑。

[self transitionFromViewController:self.currentViewController toViewController:vc duration:0.3 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{ 
     [self.currentViewController.view removeFromSuperview]; 
     vc.view.frame = self.view.bounds; 
     [self.view addSubview:vc.view]; 
     [vc setEditing:YES animated:NO]; 
     [vc viewWillAppear:NO]; 
    } completion:^(BOOL finished) { 
     [vc didMoveToParentViewController:self]; 
     [self.currentViewController removeFromParentViewController]; 
     self.currentViewController = vc; 
    }];