自定义Segue没有动画

时间:2014-11-11 19:04:51

标签: ios objective-c segue uicontainerview

我已经设置了一个自定义对话框,当按下容器视图控制器中的按钮时,通过自定义segue显示,执行函数被调用,除动画外,一切看起来都很好。

这是故事板上的segue: Here is the segue on the storyboard

这是按钮: Here is the button

以下是segue的代码:

#import "TimerDialogSegue.h"

@implementation TimerDialogSegue

-(void)perform
{
    UIViewController *dst = [self destinationViewController];
    //Doesn't appear work with the Timer View Controller as the source 
    //  so I use the parent Home View Controller
    UIViewController *src = [self sourceViewController];
    src = src.parentViewController;

    // set the view frame
    CGRect frame;
    frame.size.height = src.view.frame.size.height;
    frame.size.width = src.view.frame.size.width;
    frame.origin.x = src.view.bounds.origin.x;
    frame.origin.y = src.view.bounds.origin.y;
    dst.view.frame = frame;

    // add the view to the hierarchy and bring to front
    [src addChildViewController:dst];
    [src.view addSubview:dst.view];
    [src.view bringSubviewToFront:dst.view];

    [UIView animateWithDuration:0.3f
        animations:^
        {
            dst.view.alpha = 1.0f;
        }];
}

@end

这是Dialog的代码,它解散了它,这部分动画很好

- (IBAction)cancelButtonPressed:(id)sender
{
    [self dismiss:sender];
}

- (IBAction)dismiss:(id)sender
{
    [UIView animateWithDuration:0.3f
        animations:^
        {
            self.view.alpha = 0.0f;
        }
        completion:^(BOOL finished)
        {
            [self.view removeFromSuperview];
            [self removeFromParentViewController];
        }];
}

总结对话框出现并正常运行唯一的问题是它出现时没有动画。当它消失时它会动画。任何人都知道如何解决此问题或解决方法,以便在出现此对话框时为其设置动画?

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

你在说:

[UIView animateWithDuration:0.3f
    animations:^
    {
        dst.view.alpha = 1.0f;
    }];

但是dst.view.alpha已经1 已经,所以没有任何反应。您只能为更改设置动画。

例如,当您解雇时,您可以设置动画:

  self.view.alpha = 0.0f;

这是有效的,因为self.view.alpha1所以实际上有一个动画更改。