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!
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With