Changing animation from view to view - ios

I have a tabbar application with 4 tabs and a navigation bar hooked to one. On the tab with the navigation bar I have a button that brings you to a new page. I also have one that brings you back to the tab page, but I have a problem. When going back to the tab page the animation is going the wring way. I did this all with storyboards so no coding. I looked around and want to put this in the code:
- (void) pushController: (UIViewController*) controller
withTransition: (UIViewAnimationTransition) transition
{
[UIView beginAnimations:nil context:NULL];
[self pushViewController:controller animated:NO];
[UIView setAnimationDuration:.5];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationTransition:transition forView:self.view cache:YES];
[UIView commitAnimations];
}
But i have no idea how and where to put it in.

Take a look at this Apple guide to creating a custom segue. Your perform code would look something like this:
- (void)perform {
[UIView beginAnimations:nil context:NULL];
[self.sourceViewController.navigationController pushViewController:self.destinationViewController animated:NO];
[UIView setAnimationDuration:.5];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationTransition:transition forView:self.view cache:YES];
[UIView commitAnimations];
}
Then in your storyboard, set the type of the segue to Custom, and then enter the name of your custom segue class.

Related

UIButton not capturing touches after animating the view

In my program I use the following code to animate the self.view due to the soft keyboard covering up a UITextField at the bottom of the page.
- (IBAction)moveViewUp:(UITextField *)textField
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.25];
self.view.frame = CGRectMake(0,-150,320,400);
[UIView commitAnimations];
}
And the following code brings the view back to original position.
- (IBAction)moveViewDown:(UITextField *)textField
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.25];
self.view.frame = CGRectMake(0,0,320,400);
[UIView commitAnimations];
}
But once both methods are executed, the screen looks very normal though, a UIButton in the screen stops capturing any touches on it.
Any tips would be highly appreciated.

Implement same page transition in UIDeviceOrientationLandscapeLeft and UIDeviceOrientationLandscapeRight

I have developing project in iOS 6.0 sdk which should work on iOS4.3+ devices, in my project i am using the page curl to navigate betwwen pages , but the page curl happening in LandscapeLeft is not as same as Pagecurl in Landscape Right. I want the same page curl that is happening in Landscape Left to be in Landscape right.
Please take a look at the link for better understanding.
Video Demo Link
The code i have used is shown below
-(IBAction)nextBtnTapped {
UIDeviceOrientation deviceOrientation=[UIDevice currentDevice].orientation;
page2 *Obj=[[page2 alloc]init];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
if (deviceOrientation==UIDeviceOrientationLandscapeLeft)
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.navigationController.view cache:NO];
else if(deviceOrientation==UIDeviceOrientationLandscapeRight)
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.navigationController.view cache:NO];
[self.navigationController pushViewController:Obj animated:NO];
[UIView commitAnimations];
}
-(IBAction)prevBtnTapped {
UIDeviceOrientation deviceOrientation=[UIDevice currentDevice].orientation;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.8];
if (deviceOrientation==UIDeviceOrientationLandscapeLeft)
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.navigationController.view cache:NO];
else if(deviceOrientation==UIDeviceOrientationLandscapeRight)
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.navigationController.view cache:NO];
[self.navigationController popViewControllerAnimated:YES];
[UIView commitAnimations];
}
Can any one please tell me what wrong have i done in this code.
Any help will be appreciated.
UIDeviceOrientationLandscapeLeft with page curl is bugged. You won't get it to work correctly.

getting access EXC_BAD_ACCESS when doing animation

I am doing an animation, so when you click a button MyAccount from the first screen it will navigate you to Account View
- (void)pushToAccount
{
AccountViewController *controller = [[AccountViewController alloc] initWithNibName:#"AccountViewController" bundle:nil];
//[self.navigationController pushViewController:controller animated:NO];
[UIView beginAnimations: #"Showinfo"context: nil];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
[self.view addSubview:controller.view];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:NO];
[UIView commitAnimations];
}
However, whenever i click on the Account View Controller ( contains some buttons and images view in it ), my program is crashing at it show EXC_BAD_ACCESS at main class
Please advice me on this issue...
Your view controller is trying to animate a transition by adding another view controller's view as a subview of your current view. That's problematic on a whole bunch of dimensions. Notably, you're not doing anything with the new view controller itself ... if this was an ARC project, it will get released on you.
If you just want to transition from one view controller to another, you should generally either do a standard pushViewController:animated: or presentModalViewController:animated:. It looks like you used to do the former. Why did you replace it with the current code?
If you can tell us what you were trying to do, why you're not using the standard transitions, perhaps we can help you further.
Update:
If you don't like the default animation, but rather want some custom animation to your transition, you can do something like:
CustomAnimationViewController *yourNewViewController = [[CustomAnimationViewController alloc] initWithNibName:#"CustomAnimationView" bundle:nil];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
[self.navigationController pushViewController:yourNewViewController animated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
// if you're using ARC, you don't need this following release, but if you're not using ARC, remember to release it
// [yourNewViewController release];
Update 2:
And, anticipating the logical follow-up question, how do you animate the dismissal of the new view controller, you might, for example have a "done" button that invokes a method like the following:
- (IBAction)doneButton:(id)sender
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelay:0.375];
[self.navigationController popViewControllerAnimated:NO];
[UIView commitAnimations];
}
My guess is that you have a UIButton that will call your pushToAccount method when pressed and that when it is pressed it cannot find that method. It coud be because the method signature does not include an object. So if you change your method from
- (void)pushToAccount
to
- (void)pushToAccount:(id)sender
It may fix your problem. It is also important to make sure that the object that contains the pushToAccount method isn't dealloc'd before that method is called. Perhaps put an NSLog message or a breakpoint inside dealloc to make sure it isn't called.
i think use bellow line
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.window cache:YES];
insted of your bellow line..
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:NO];
hope this help you...
:)
and also for animation use bellow code if required....
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setType:kCATransitionFromBottom];
[animation setDuration:1.0];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:
kCAMediaTimingFunctionEaseInEaseOut]];
[[self.window layer] addAnimation:animation forKey:kAnimationKey];
here use your view insted of window otherwise windows workfine..
:)

Is moving between iOS subviews within a single view possible without returning to the view?

Is moving between iOS subviews within a single view possible without returning to the view? If so, how? Code example welcome.
How I'm doing it now but this requires returning to the "home" view:
In the myFile.m
// Define the other views
DF_Results *df_Results;
CR_FiringRange *cr_FiringRange;
CR_AssetLoader *cr_AssetLoader;
DB_GeneralData *db_GeneralData;
DB_ArmorData *db_ArmorData;
DB_WeaponsData *db_WeaponsData;
#synthesize ScreenButton01;
#synthesize ScreenButton02;
#synthesize ScreenButton03;
#synthesize ScreenButton04;
#synthesize ScreenButton05;
#synthesize ScreenButton06;
#synthesize ScreenButton07;
.
.
.
-(IBAction) ScreenButton02Clicked:(id) sender {
df_Results = [[DF_Results alloc]
initWithNibName:#"DF_Results"
bundle:nil];
[UIView beginAnimations:#"flipping view" context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
[self.view addSubview:df_Results.view];
[UIView commitAnimations];
}
In DF_Results to return we tap another button but I would like to be able to jump straight to another subview:
-(IBAction) ResultsScreenButton01Clicked:(id) sender {
[UIView beginAnimations:#"flipping view" context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view.superview cache:YES];
[self.view removeFromSuperview];
[UIView commitAnimations];
}
In iOS 4.0 UIView has a number of block based animation transitions tasks which according to docs are the recommended approach. E.g. this one could be useful:
(void)transitionFromView:(UIView *)fromView toView:(UIView *)toView duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void (^)(BOOL finished))completion
See UIView docs for more details.

Can I "curl down" a page on popViewControllerAnimated?

I can "curl up" a view controller with this code:
[UIView beginAnimations:#"animation" context:nil];
[self.navigationController pushViewController:page animated:NO];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
but I can't curl down the last page like this:
[UIView beginAnimations:#"animation" context:nil];
[self.navigationController popViewControllerAnimated:NO];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
any idea why not? I just really want to "reverse" the animation (as if a sticker has been peeled off to show the 'push'ed view controller and stuck back on when they click a button).
Thanks
Ok, my old answer was totally wrong...
the problem is that you are popping the view controller before setting the transition view. If you change the code to this:
[UIView beginAnimations:#"animation" context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.navigationController.view cache:NO];
[self.navigationController popViewControllerAnimated:NO];
[UIView commitAnimations];
it works fine
Using OpenGL or a lot of complex CoreAnimation processes, I am sure that you could, but, It would be a lot of hassle for doing something like that. Something that might help you along: A simple book turning application written entirely with CoreAnimation

Resources