简体   繁体   中英

Custom Segue doesn't animate

I have set up a custom dialog to appear via a custom segue when a button in a container view controller is pressed, the perform function is being called and everything appears to work just fine except for the animation.

Here is the segue on the storyboard: 这是情节提要上的剧情

Here is the button: 这是按钮

Here is the code for the 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

Here is the code from the Dialog that dismisses it, this part animates just fine

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

To summarize the Dialog appears and operates correctly the only issue is there is no animation when it appears. It does animate when it disappears. Anyone know how I might fix this or a workaround to animate this Dialog when it appears?

Thanks in advance for any help.

You are saying:

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

But dst.view.alpha is 1 already so nothing happens. You can only animate a change .

For example, when you dismiss, you animate this:

  self.view.alpha = 0.0f;

That works because self.view.alpha was 1 so there is actually a change to animate.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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