I create two page VC that has tableView and push style transition together.
I want custom back button push style transition that when return pervious page this page reload again and receive data again.
If a custom transition is what you need you can start off with:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationOptionTransitionFlipFromBottom forView:[[self navigationController] view] cache:YES];
[[self navigationController] popViewControllerAnimated:NO];
[UIView commitAnimations];
You can create a custom button on the navigation bar that replaces the backbutton with hidesBackButton set to YES and then just make it perform a custom segue.
Related
I have a problem :D.
I'm currently using a SplitViewController. At the start I want to hide the TableViewController in the MasterView. So i decided to add a SubView in the Storyboard into the tableView, where a little label will be shown.
So after I make my choice in the DetailView and click the Button I want to hide the subView and want to show the tableView. That all with animations.
So here is my Code:
In the TestTableViewController.m
-(void)AnimateView{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.1];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
fixedView.frame=CGRectMake(-500, 0,0,0);
[UIView commitAnimations];
NSLog(#"test");
And in the TestDetailViewController.m
- (IBAction)attractionButton:(UIButton *)sender
{
TestTableViewController *testTableViewController = [[TestTableViewController alloc]init];
[testTableViewController AnimateView];
}
I get the NSLog "test" but the Animation is not working.
fixedView is my Subview and I drag it to the header file so it's an IBOutlet.
Thank you so far.
So you seem to instantiate a new ViewController and trying to perform this animation straight away:
TestTableViewController *testTableViewController = [[TestTableViewController alloc]init];
[testTableViewController AnimateView];
The problem is that you don't even present that view controller (its view is not on screen anywhere) so it's normal you don't see any animation.
From my understanding you already have another instance of this view controller presented on screen (am I right?) - so that is the one that you need to use. Pass its pointer to TestDetailViewController in some way (e.g. a property) and then use that object to call your animation method.
PS. I would recommend naming all your methods starting with a lower case letter ;)
The problem is, you are not referencing the same master view controller in your details view controller.
You are creating another one in your IBAction.
In order to get a hold of your (the "original" one) master view controller, do this in your detail view controller:
Create a ivar:
TestTableViewController *masterViewController;
And then to reference it:
masterViewController = (TestTableViewController*)[[[self.splitViewController.viewControllers lastObject] viewControllers] objectAtIndex:0];
For example:
- (IBAction)attractionButton:(UIButton *)sender
{
masterViewController = (TestTableViewController*)[[[self.splitViewController.viewControllers lastObject] viewControllers] objectAtIndex:0];
[masterViewController AnimateView];
}
And finally in your AnimateView method, make change to the following:
[UIView animateWithDuration:0.1f animations:^
{
fixedView.frame = CGRectMake(-500, 0, 0, 0);
}
completion:nil];
Hope this helps.
What you could try is this:
[UIView animateWithDuration:0.15f animations:^{
fixedView.frame=CGRectMake(-500, 0,0,0);
}completion:^(BOOL finished){
}];
Are you sure you can call [UIView beginAnimations: ....] without a first argument?
my app is navigation based, i am adding a child view controller to one of my screens like so :
[self addChildViewController:_settingsVc];
[_settingsVc didMoveToParentViewController:self];
[self.view addSubview:_settingsVc.view];
[UIView transitionFromView:self.view toView:_settingsVc.view
duration:0.6
options:UIViewAnimationOptionTransitionFlipFromLeft
completion:^(BOOL finished) {
_header_view.header_title.text = #"Settings";
}];
the view and animation shows great! and when i am returning like so from the presented child view controller :
[UIView transitionFromView:_settingsVc.view toView:self.view
duration:0.6
options:UIViewAnimationOptionTransitionFlipFromRight
completion:^(BOOL finished) {
_header_view.header_title.text = #"Friends Locator";
}];
i goes well too... the problem is if i am entering to the child view controller and hit the back button of the UINavigationBar then i can see the bar slides out and i got black screen.
how can i manage this?
The back button is do UINavigationController pop animation. You can try add a leftBarButtonItem that set a customView which is a UIButton, and add your own back animation in the button click event.
I am developing iPad application using UISplitViewController. I want to show/hide Master View Controller on demand. I have seen How to hide & unhide Master View Controller in SplitView Controller and Animate visibility of master detail controller of UISplitViewController, so I came up with something like this:
I have hideMasterView BOOL variable in my UISplitViewControllerDelegate and when I want to show/hide Master View I call:
hideMasterView = !hideMasterView;
[UIView animateWithDuration:0.25
delay:0.0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
[self.splitViewController willAnimateRotationToInterfaceOrientation:self.interfaceOrientation duration:0];
[self.splitViewController willRotateToInterfaceOrientation:self.interfaceOrientation duration:0];
[self.splitViewController didRotateFromInterfaceOrientation:self.interfaceOrientation];
[self.splitViewController viewWillLayoutSubviews];
[self.splitViewController.view layoutSubviews];
}
completion:^(BOOL finished) {}];
And my delegate has method:
- (BOOL)splitViewController:(UISplitViewController *)svc
shouldHideViewController:(UIViewController *)vc
inOrientation:(UIInterfaceOrientation)orientation{
return hideMasterView;
}
It works, but animation is not quite smooth. On hide everything works fine, but when Master View is being shown, Detail View is resized before sliding, leaving blank gray space on right and sliding on it afterwards.
How to fix this animation?
I built a app with storyboard, with an initial view controller, connected to many subsequent view controllers, connected sequentially, using cross dissolve segue. These work one swipes. All works fine. However, instead of being forced to use the basic segues, I want to have a custom segue that will slide the view controller content on and off the screen, much like the push for navigationControllers, but, being enabled to go left and right depending if one is going forward or backwards in the app.
I have set the segue to custom, and have created and saved a MySegue.h file. HOWEVER, I don't know how to code a custom segue that will slide one viewcontroller off the screen as the other slides on and back and forth as I move between view controllers.
Can anyone please provide me with come coding (it should be easy!) for a custom segue to move from one view controller to the next and back by sliding the screen on and off so I don't have to use the basic cross dissolve or standard flips offered in Xcode 4.2? I would be most grateful.
I was running into the same issue here, but I was using swipe gestures to go from one view controller to the next. Using the storyboard itself to set up segues was working fine, but when I needed a swipe to "go back" to the previous view controller, the animation went from right-to-left, instead of left-to-right. To fix that issue I did the following:
Embedded a Navigation Controller in the root view controller.
Used segues to push new view controllers.
When I wanted to "go back" to the previous view controller, I did not add a segue to the storyboard to push the previous view controller. Instead, I called the Navigation Controller's popViewControllerAnimated method whenever a back swipe occurred.
To create a custom segue that slides view controllers first create a class that extends UIStoryboardSegue, then override the perform selector. I just made something like this and it should work for you too. Here's my code:
#define kAnimationDuration 0.5
#import "CustomSlideSegue.h"
#implementation CustomSlideSegue
- (void)perform
{
UIViewController *sourceViewController = (UIViewController *) self.sourceViewController;
UIViewController *destinationViewController = (UIViewController *) self.destinationViewController;
[sourceViewController.view addSubview:destinationViewController.view];
[destinationViewController.view setFrame:sourceViewController.view.window.frame];
[destinationViewController.view setBounds:sourceViewController.view.bounds];
CGSize screenSize = [[UIScreen mainScreen] bounds].size;
if ( !self.slideLeft ) {
[UIView animateWithDuration:kAnimationDuration
delay:0.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
[destinationViewController.view setCenter:CGPointMake(screenSize.height + screenSize.height/2, screenSize.height/2 - 138)];
[destinationViewController.view setCenter:CGPointMake(screenSize.width/2 + 127, screenSize.height/2 - 138)];
}
completion:^(BOOL finished){
[destinationViewController.view removeFromSuperview];
[sourceViewController presentViewController:destinationViewController animated:NO completion:nil];
}];
} else {
[UIView animateWithDuration:kAnimationDuration
delay:0.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
[destinationViewController.view setCenter:CGPointMake(-1*screenSize.height/2, screenSize.height/2 - 138)];
[destinationViewController.view setCenter:CGPointMake(screenSize.width/2 + 127, screenSize.height/2 - 138)];
}
completion:^(BOOL finished){
[destinationViewController.view removeFromSuperview];
[sourceViewController presentViewController:destinationViewController animated:NO completion:nil];
}];
}
}
Then when you want to perform the segue use this code:
UIViewController *destination = [self.storyboard instantiateViewControllerWithIdentifier:#"some identifier"];
CustomZoomSegue *segue = [[CustomZoomSegue alloc] initWithIdentifier:#"segue vc identifier" source:self destination:destination];
[self prepareForSegue:segue sender:self];
[segue perform];
The CGPointMake calls are custom to my code (I used landscape orientation) but you should be able to change it to fit your needs. If you need further clarification or have any question let me know and I will try to answer.
NOTE: I use storyboards with no segue lines between the view controllers.
Why not just use a UINavigationController? This seems to be exactly what they're designed for.
I have 2 views, login and register.
I did [currentTextField resignFirstResponder]; before I navigates to the other view.
The problem is, the keyboard is only hidden after it switched view. Which thus fired the keyboardDidShow method on the other view which messes stuff up.
2011-07-19 18:55:33.315 Prime Taxi Booking[601:207] Login view appear // lauched app
2011-07-19 18:55:34.952 Prime Taxi Booking[601:207] Login Keyboard appear // starts typing
2011-07-19 18:55:37.033 Prime Taxi Booking[601:207] Register view appeared // navigation
2011-07-19 18:55:37.036 Prime Taxi Booking[601:207] Login view disappear
2011-07-19 18:55:37.360 Prime Taxi Booking[601:207] Register Keyboard disappear // ?? how do I make this to disappear login keyboard instead?
I wonder why did it only resignFirstResponder after switching views when I clearly placed it above it.
-(IBAction) registerButton:(id) sender
{
[currentTextField resignFirstResponder];
Registers *registerview = [[Registers alloc] initWithNibName:nil bundle:nil];
[UIView beginAnimations:#"flipping view" context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationTransition: UIViewAnimationTransitionCurlUp
forView:self.view.superview
cache:YES];
[UIView commitAnimations];
[self presentModalViewController:registerview animated:YES];
//[self.view addSubview:registerview.view];
}
you can put some delay before going to second view so that keyboard will hide. try [self performSelector: withObject: afterDelay:0.35];//Pass the selector like #selector(displaySecondView) before calling this resign current textfield.