navigationController setup pop transition style - objective-c

Is it possible to change popToViewController transition style for UINavigationController? I need the same style as for pushViewController method?(I mean from right to left style(pushViewController), not left to right(popToViewController by default)).

For modally presented view controllers, you can change the animation with the modalTransitionStyle property. AFAIK, there is no way to change a navigation controller's push animation (except rebuilding UINavigationController from scratch).
https://github.com/devindoty/iOS-Transition-Pack
OR
[UIView beginAnimations:#"animation" context:nil];
[self.navigationController pushViewController: yourviewcontroller animated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[UIView commitAnimations];

Related

How do I stop a hidden UIView from making UITextFields unclickable?

I have a UITextfield dedicated to dates. When clicked I have a method that shows a UIView with a UIDatePicker as a subview and a method to hide it again. By default this UIView is hidden.
I've noticed that the textfields of my form are no longer clickable. However my UIButtons are still working.
The UIView is a subview of the superview that the UITextFields and UIButtons are also part of. The UIView also takes up the whole area of the window.
The UIView is an outlet also.
Does anyone have any idea what is happening here?
Kind regard
Code:
- (void) hidePickerView {
[UIView animateWithDuration:0.5
animations:^{
[[self datePickerView] setFrame:CGRectMake(0, -250, 320, 50)];
} completion:^(BOOL finished) {
[[self datePickerView] removeFromSuperview];
}];
}
I've also tried putting the following in my viewDidLoad method:
[[self datePickerView] removeFromSuperview];
I was returning NO in my - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField method. Setting this to yes solved the problem.

Transitioning from UIImagePickerController to a second UIViewController

Still feeling pretty green in Objective-C - building my first "real" project and hit an architectural snag early on..
I'd like to present my views and navigation in a fully 'custom' environment - e.g. something where I hide all of the built-in UI controls (e.g. UINavigationController or UITabBar). One specific example (as in the title): moving from a 'main' view directly to a UIImagePickerController, and then right from the UIImagePickerController to a new third view.
Here are the three primary view controllers I'm working with:
MainViewController (custom subclass of UIViewController, contains my main Nav and is in general my primary or 'parent' controller)
ImageEditViewController (custom subclass of UIViewController wherein I overlay some controls on top of a stored image)
UIImagePickerController (built-in Apple class)
There are a couple of approaches I can image for this (but I can't figure out how to do either one):
Use a UINavigationController or UITabBar implementation, but somehow hide the system UI controls and implement my own. I am blocked on this approach because - simply - I don't know how to hide the system UI controls.
Call controller-to-controller or view-to-view transitions manually at specific points in the code. I sort of prefer this method but I can't figure out the best 'approach' to instantiating and managing and transitioning between my controllers. Example of things I don't know: how do I call a second view controller from my main view controller? How do I call a third view controller directly from the second? (Or at least transition to the third directly!)
I assume there is an easy solution here; just something I haven't learned yet about managing views and view controllers outside of Apple's helper classes.
What system UI controls are you talking about? The navigation bar?
You can just do myNavigationController.navigationBarHidden = YES; for a UINavigationCOntroller.
Documentation here.
As for the kind of navigation you should have, that really depends on your use case. Are you trying to achieve a hierarchy or workflow? Then perhaps a navigation controller is what you want. Is each view controller a separate piece that does not necessarily follow a workflow? Then a tab bar controller could work.
For tab bar you should be able to do something like:
myTabBarController.tabBar.hidden = YES;
[[myTabBarController.view.subviews objectAtIndex:0] setFrame:CGRectMake(0, 0, 320, 480)]; // or whatever your screen dimensions are
1.
For hiding navigation bar, it's quite easy:
self.navigationController.navigationBarHidden = YES;
For Hiding TabBar Use this:
- (void) hideTabBar:(UITabBarController *) tabbarcontroller {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
for(UIView *view in tabbarcontroller.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
}
}
[UIView commitAnimations];
}
- (void) showTabBar:(UITabBarController *) tabbarcontroller {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
for(UIView *view in tabbarcontroller.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(view.frame.origin.x, 431, view.frame.size.width, view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 431)];
}
}
[UIView commitAnimations];
}
2.
If you want to easily be able to navigate backwards you should use a navigation controller, it will allow you to pop the view controller when you are done with it. Or you can do something like this (outside of navigation controller):
CustomViewController *controller = [[CustomViewController alloc] init];
[self presentModalViewController:controller animated:YES];

Update interface orientation manually in iOS

My iOS application supports all orientations except PortraitUpsideDown.
But in the application I have an view with preferences which I want it to only be shown in Portrait orientation. So whenever this view is shown, it is rotated if needed, to be in portrait mode. That means that user will rotate device in portrait mode also, to setup preferences, and then after closing this view interface should now have portrait orientation.
The problem is, that after preferences view is hidden interface stays in landscape orientation, since I block autorotation after this view is shown.
So after the view is hidden I want to manually update the interface to current device orientation. How can I do it?
self.view.hidden=NO;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
self.view.alpha=1.0;
[UIView commitAnimations];
This code is called from the OptionsViewController after a LongPressGesture on its superview.
I created a UIViewController extension to force update of orientation of a controller, based on the solution presented by Marek R. Since the new versions of iOS, his solution does not work anymore. I post here my solution to force orientation update (in order to take into account supported orientation methods of controller) without having side visual effects. Hope it helps.
UIViewController *vc = [[UIViewController alloc]init];
[[vc view] setBackgroundColor:[UIColor clearColor]];
[vc setModalPresentationStyle:(UIModalPresentationOverFullScreen)];
[self presentViewController:vc animated:NO completion:^{
dispatch_async(dispatch_get_main_queue(), ^{
[vc dismissViewControllerAnimated:YES completion:completion];
});
}];
All you have to do is add the following to the view controller you're using for your preferences.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
Calling this workaround works for me:
-(void)forceOrientationUpdate {
UIViewController *c = [[UIViewController alloc]init];
[self presentModalViewController:c animated:NO];
[self dismissModalViewControllerAnimated:NO];
[c release];
}

- (void)viewWillAppear:(BOOL)animated detect custom animation

I have a button which when pressed pushes a view controller however i'm using a custom animation so pushViewController: childController animated: is set to NO. What i want to do though is detect this custom animation in my - (void)viewWillAppear:(BOOL)animatedmethod and write an if statement like this;
- (void)viewWillAppear:(BOOL)animated {
if (customAnimation occured) {//Do this}
else {//Do this}
}
This is the method for my button which pushes the view controller.
- (void)nextPressed:(id)sender {
childController = [[CategoryOneDetailController alloc] initWithNibName:xibDownName bundle:nil];
[UIView beginAnimations: #"Showinfo"context: nil];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
[self.navigationController pushViewController: childController animated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
[childController release];
}
Any help would be much appreciated, thanks, Sami.
If you don't use standard animations, I think your best bet is to add a property to your pushed view controller that is set to YES in case of a custom animation (and NO by default to not break any existing behavior). Then you can check that property in viewDidAppear:.
If you need your custom logic to be executed after the animation has run, you might want to set up an animation completion handler or block.

viewWillAppear-related problem

Without giving you all my code examples, I'll made this quick.
Has this ever happened to one of you to get viewWillAppear called only the first time it shows up?
I have this problem with all my view.
For example: When my app starts, I get to the StartView which is a main menu. (viewWillAppear gets called) then I press on one button that'll show a navigation controller (viewWillAppear gets called). Then I get back to the main menu (it does not get called) and then I press on the same navigation controller again and it does not get called.
It would be awesome if someone could points me somewhere, I've been searching for this since two days now...
Also if you need more code samples, I can give you some.
For further reading:
That's how I call my navigation controller:
PremierSoinsAppDelegate *AppDelegate = (PremierSoinsAppDelegate *)[[UIApplication sharedApplication] delegate];
UIView *newView = [AppDelegate.navigationController view];
[newView setFrame:CGRectMake(320.0f, 0.0f, 320.0f, 480.0f)];
[UIView beginAnimations:#"RootViewController" context:nil];
[UIView setAnimationDuration:0.3];
newView setFrame:CGRectMake(0.0f, 0.0f, 320.0f, 480.0f)];
UIView commitAnimations];
[AppDelegate.window addSubview:newView];
[AppDelegate.window makeKeyAndVisible];
And that's how I show my menu back:
PremierSoinsAppDelegate *AppDelegate = (PremierSoinsAppDelegate *)[[UIApplication sharedApplication] delegate];
UIView *newView = [AppDelegate.startViewController view];
newView setFrame:CGRectMake(-320.0f, 0.0f, 320.0f, 480.0f)];
UIView beginAnimations:#"StartViewController" context:nil];
UIView setAnimationDuration:0.3];
newView setFrame:CGRectMake(0.0f, 0.0f, 320.0f, 480.0f)];
[UIView commitAnimations];
[AppDelegate.window addSubview:newView];
[AppDelegate.window makeKeyAndVisible];
Thanks A LOT.
You can implement the UINavigationControllerDelegate in your Nav Controller to propagate the viewWillAppear: messages down. You can implement the message like this:
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
if ([viewController respondsToSelector:#selector(viewDidAppear:)]) {
[viewController viewDidAppear:animated];
}
}
Note that this is the viewDidAppear and not ViewWillAppear version, but they're basically the same.
However, you should note that the fact that you need to do this may be a sign that something else is wrong in your controller/view code and you might want to reask the question giving us more context to answer it. In particular, I'm assuming that somewhere outside of the code you're giving us, you're pushing and popping view controllers as per usual for a Nav Controller.
viewWill/DidAppear: will only be called when using a UINavigationController or UITabBarController (or really any system-provided-viewControlller managing class) to manipulate views. If you're manually doing this (as you seem to do in your second code snippet, these messages won't get sent.