Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
475 views
in Technique[技术] by (71.8m points)

ipad - How do you perform a customized segue (modal segue) from a UIButton in storyboard

I would like to segue a destination scene through a button present in source scene. I also would like to have a control of the transition animation between the viewcontroller (I want to animate the 2 views from right to left). Is it possible to do so through the replace segue? I try both the replace segue and the push segue but the segue is not happening any suggestion how i should proceed there? Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I found out that the replace segue and push segue were misleading because the replace seems to be available for a master detail controller and the push segue for a navigation controller only. In this case I needed to implement a customize segue instead. You need to subclass the UIStoryboardSegue and override the perform segue.

Here is an e.g of my code:

-(void)perform{
    UIView *sourceView = [[self sourceViewController] view];
    UIView *destinationView = [[self destinationViewController] view];      

    UIImageView *sourceImageView;
    sourceImageView = [[UIImageView alloc] 
                       initWithImage:[sourceView pw_imageSnapshot]];

    // force the destination to be in landscape before screenshot
    destinationView.frame = CGRectMake(0, 0, 1024, 748);
    CGRect originalFrame = destinationView.frame;
    CGRect offsetFrame = CGRectOffset(originalFrame, originalFrame.size.width, 0);


    UIImageView *destinationImageView;
    destinationImageView = [[UIImageView alloc] 
                            initWithImage:[destinationView pw_imageSnapshot]];

    destinationImageView.frame = offsetFrame;  
    [self.sourceViewController presentModalViewController:self.destinationViewController animated:NO];

    [destinationView addSubview:sourceImageView];                        
    [destinationView addSubview:destinationImageView]; 

    void (^animations)(void) = ^ {                                     
        [destinationImageView setFrame:originalFrame];

    };

    void (^completion)(BOOL) = ^(BOOL finished) {                       
        if (finished) {

            [sourceImageView removeFromSuperview];
            [destinationImageView removeFromSuperview];

        }
    };

    [UIView animateWithDuration:kAnimationDuration delay:.0 options:UIViewAnimationOptionCurveEaseOut animations:animations completion:completion];
 }

The main idea is to create a screenshot view of the source and destination scene; add them to the destination scene view, control the animation of those two views, call to the presentModalViewController function on the sourceviewController and remove the two screenshots views when done with the animation.

One can found an example of implementing a screenshot utility function here in Ch15 of this link: http://learnipadprogramming.com/source-code/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...