简体   繁体   English

在UISegment控件中设置编辑

[英]setting editing within a UISegment Control

I am writing a universal app using both UISplitViewController and a UISegmentedControl. 我正在使用UISplitViewController和UISegmentedControl编写通用应用程序。 Each controller in the UISegmentedControl allows editing. UISegmentedControl中的每个控制器都允许编辑。 It appears that the editing state of the controllers must be re-established when a segment becomes the current segment. 看起来当一个段成为当前段时,必须重新建立控制器的编辑状态。 My problem is strange animations that result from [vc setEditing:YES animation:NO] . 我的问题是[vc setEditing:YES animation:NO]导致的奇怪动画。 Can someone suggest how I might avoid this? 有人可以建议我如何避免这种情况吗? Thank you. 谢谢。

- (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;
    }];

To avoid inappropriate animations, I completed the preparation preparation for display of the Controller with setEditing and viewWillAppear. 为了避免出现不适当的动画,我使用setEditing和viewWillAppear完成了显示Controller的准备工作。

   [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;
    }];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM