自定义Segue动画闪烁

时间:2014-10-21 16:02:26

标签: ios objective-c animation uistoryboardsegue

我正在使用UISplitViewController构建一个应用程序作为我的根视图控制器(由Apple规定)。但是,我需要在UISplitViewController之前显示登录/管理的自定义视图,因此我创建了一个自定义UIStoryboardSegue来调用一些自定义动画。我试图通过模态segue重新创建push / pop segues,而不是实际推送一个弹出的视图控制器。我已经正确地实现了一切,但是,在动画结束时我有一个闪烁。这是它的gif:

Gif of animation

这是我的自定义Segue的代码:

- (void)perform {

    UIViewController *srcViewController = (UIViewController *) self.sourceViewController;
    UIViewController *destViewController = self.destinationViewController;

    UIView *prevView = srcViewController.view;

    UIView *destView = destViewController.view;

    UIWindow *window = [[[UIApplication sharedApplication] delegate] window];



    [window insertSubview:destView aboveSubview:prevView];

    [destView enterRight:0.1 then:^{
        [destView removeFromSuperview];
        [srcViewController.presentingViewController dismissViewControllerAnimated: NO completion:nil];

    }];
}

这是我的自定义动画(在UIView上实现的类别):

-(void)enterRight:(float)delay then:(void(^)(void))after
{
    CGPoint moveTo = self.center;
    CGPoint moveFrom = self.center;


    // Grab a point from off the screen
    CGFloat simpleOffscreen = [UIScreen mainScreen].bounds.size.width;


    // come from off the right side (+)
    moveFrom.x = moveFrom.x + simpleOffscreen;

    self.center = moveFrom;
    self.hidden = NO;

    [UIView animateWithDuration:0.5
                          delay:delay
         usingSpringWithDamping:1
          initialSpringVelocity:0.1
                        options:UIViewAnimationOptionCurveEaseIn
                     animations:^
     {
         self.center = moveTo;
     }
                     completion:^(BOOL finished)
     {
         if (after) after();
     }
     ];
}

正如你在Segue中看到的那样,我将视图设置为当前视图控制器的动画,然后没有动画呈现实际的目标视图控制器。我认为这是引入闪烁的地方,但我不确定如何防止这种情况发生。

此自定义segue的故事板为Here

任何人都知道如何实现这个目标?

0 个答案:

没有答案
相关问题