Custom Segue with UIViewAnimationOptionTransitionCurlDown - objective-c

I'd like create a custom segue to swap ViewControllers with a curl up animation but I can't find a way, What would be the -(void)perform for this?
I've got this
-(void)perform{
UIViewController *dst = [self destinationViewController];
UIViewController *src = [self sourceViewController];
[UIView beginAnimations:nil context:nil];
//change to set the time
[UIView setAnimationDuration:1];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:src.view cache:YES];
[UIView commitAnimations];
}
But I don't get to change the view, anyway thanks for your help!

Nevermind, I solved it, for the record the only thing I had to do was add a Navigation Controller and then I could use custom segues like:
- (void) perform {
UIViewController *src = (UIViewController *) self.sourceViewController;
UIViewController *dst = (UIViewController *) self.destinationViewController;
[UIView transitionWithView:src.navigationController.view duration:0.3
options:UIViewAnimationOptionTransitionFlipFromBottom
animations:^{
[src.navigationController pushViewController:dst animated:NO];
}
completion:NULL];
}

Related

Flip transition between storyboard view controllers not working

I'm having a lot of trouble setting a flip transition between storyboards. The app crashes when the method below is called. I'm getting the error message:
[NSPathStore2 setView:]: unrecognized selector sent to instance...
This is my code:
- (void)advanceToNextViewController {
humptyDumptyViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:#"firstStoryVC"];
/*
[self.navigationController pushViewController:controller animated:YES];
*/
[UIView beginAnimations:#"animation" context:nil];
[self.navigationController pushViewController:controller animated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
}
I'd appreciate any help with this.
Since you are using storyboard. This is more accurate, try this:
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:#"firstStoryVC"];
vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:vc animated:YES completion:NULL];
But be sure to name your view's identifier "firstStoryVC" otherwise it will crash and wont work.
Then when you want to dimiss the view:
[self dismissModalViewControllerAnimated:YES];
Try this one , it will give you full control over timings and animation.
humptyDumptyViewController *controller = [self.storyboardinstantiateViewControllerWithIdentifier:#"firstStoryVC"];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
[self.navigationController pushViewController:controller animated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[UIView commitAnimations];

UIViewAnimationTransitionCurl in left and right direction

Is there any way possible to use UIViewAnimationTransitionCurl in left and right directions? I'm looking for something similar to the Contacts app:
If you are targetting iOS 5, use UIPageViewController. The last fifteen minutes of the Implementing UIViewController Containment video from WWDC 2011 describe how to use it.
If you don't mind iOS 5 as a requirement you could use the new UIPageViewController
Otherwise you could try something like this:
self.appDelegate = [[UIApplication sharedApplication] delegate];
UIViewController *srcViewController = (UIViewController *) self.sourceViewController;
UIViewController *destViewController = (UIViewController *) self.destinationViewController;
[UIView commitAnimations];
[UIView beginAnimations:#"View Flip" context:nil];
[UIView setAnimationDuration:1.25];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight forView:self.appDelegate.window.rootViewController.view.superview cache:YES];
[srcViewController.view removeFromSuperview];
[UIView commitAnimations];
[self.appDelegate.window addSubview:destViewController.view];
self.appDelegate.window.rootViewController=destViewController;
Cheers....

UIActivityIndicator does not animate

- (void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
self.connectionIndicator = [[[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray] autorelease];
[self.view addSubview:connectionIndicator];
[self.connectionIndicator setCenter:CGPointMake(self.view.frame.size.width/2, 15)];
[connectionIndicator startAnimating];
}
The spinner shows up frozen, and does not start animating.
Edit: Okay I figured out the cause but yet to find a solution.
This view controller is pushed into navigation controller stack through a page curl-up transition:
ServerHandshakeViewController *shvc = [[ServerHandshakeViewController alloc] initWithHost:h];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1.0];
[self.navigationController pushViewController:shvc animated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
[shvc release];
Removing the above curl-up transition like below solves the spinner freeze problem.
ServerHandshakeViewController *shvc = [[ServerHandshakeViewController alloc] initWithHost:h];
[self.navigationController pushViewController:shvc animated:NO];
[shvc release];
But then, what if I want to retain my curl-up page transition?
You could try using the block method where you can specify animation options. UIViewAnimationOptionAllowAnimatedContent is the option which should free up the spinner.
[UIView transitionWithView:self.navigationController.view
duration:1.0
options:UIViewAnimationOptionAllowAnimatedContent | UIViewAnimationTransitionCurlUp | UIViewAnimationOptionCurveEaseInOut
animations:^{[self.navigationController pushViewController:shvc animated:NO];}
completion:nil];

How to remove previous ViewController?

Seeking help.
My Project:
i make a book for children.
Every page is a custom ViewController.
On every Page i have a button for next and previous Page.
When the NextPage-Button is pressed I "switch"/add a ViewController in the AppDelegate like this:
- (void)goToNextPage2 {
self.view2 = [[ViewController2 alloc] init];
view2.view.frame = CGRectMake(769, 0, 768, 1024);
[window addSubview:view2.view];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.5];
view2.view.frame = CGRectMake(0, 0, 768, 1024);
[UIView commitAnimations];
}
How and where do i remove the previous Viewcontroller?
In this case it would be ViewController1.
Any idea?
Thanks in advance
Planky
You didn't provide much information...
Anyway, that might help.
In your animation code:
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(animationDidStop:finished:context:)];
And add that to remove the ViewController:
- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
[self.view1.view removeFromSuperview];
self.view1 = nil;
}

Handling Device orientation problem for swapped views

i'm doing an ipad application, in which i have say two views
mainview and aboutus view
on startup i put the mainview in the rootcontroller's view (the one that is added to the window) alone.
and there's a button on mainview, that, when pressed, will remove the mainview from superview and put the aboutusview instead. aboutus has a similar button that gets us back to mainview.
Now the problem lies in the rotation (orientation).
when i detect an orientation change, i update the displayed view. works fine. (for mainview and aboutusview)
But if i rotate once any view, and then then try to see the second view. it seems that the second view is not autosizing.
CODE in rootViewController:
- (void)viewDidLoad
{
[super viewDidLoad];
_currentOrientation=UIDeviceOrientationPortrait;
[self.view addSubview:_mainView];
[_splashView removeFromSuperview];
}
-(void)viewDidAppear:(BOOL)animated
{
_currentView = _mainView;
}
-(void)toggleMainPage
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:.5];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:[self view] cache:YES];
[_infoView removeFromSuperview];
[self.view addSubview:_mainView];
_currentView=_mainView;
[self transformViewAccordingToOrientation:_currentOrientation];
[UIView commitAnimations];
}
-(void)toggleAboutPage
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:.5];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:[self view] cache:YES];
[_mainView removeFromSuperview];
[self.view addSubview:_infoView];
_currentView=_infoView;
[self transformViewAccordingToOrientation:_currentOrientation];
[UIView commitAnimations];
}
-(void) transformViewAccordingToOrientation:(UIDeviceOrientation)toInterfaceOrientation
{
if(toInterfaceOrientation == UIDeviceOrientationPortrait)
{
[_mainBtnCustom setBackgroundImage:[UIImage imageNamed:#"main.png"] forState:UIControlStateNormal];
_infoImage.image = [UIImage imageNamed:#"about.png"];
}else
{
[_mainBtnCustom setBackgroundImage:[UIImage imageNamed:#"mainr.png"] forState:UIControlStateNormal];
_infoImage.image = [UIImage imageNamed:#"aboutr.png"];
}
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[self transformViewAccordingToOrientation:toInterfaceOrientation];
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
_currentOrientation = [UIDevice currentDevice].orientation;
[self transformViewAccordingToOrientation:_currentOrientation];
}
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (_currentOrientation !=interfaceOrientation);
}
what am i doing wrong?