UIPageViewController alternative with standard slide transition animation for iOS 5 - ios5

I'm making an app for iOS 5 which displays one UIViewController at a time with no navigation bar.
UIPageViewController is almost perfect for what I want to achieve except it only provides the page curl transition animation for iOS 5.
I found an alternative but it's a bit of a hack. I created a UINavigationController and set the navigation bar to hidden.
When navigating forward I call
[navigationController setViewControllers:#[newVC] animated:YES];
And when navigating back I call
[self.navigationController setViewControllers:#[prevVC, currentVC] animated:NO];
[self.navigationController popViewControllerAnimated:YES];
This hack seems to work and gives me the exact transition I want, but there has to be a better way.
I'm thinking another alternative will be to use UIView animation blocks. But that will require a bit more work.

It looks like I should be able to achieve what I'm after using these two functions in UIViewController:
addChildViewController:
and
transitionFromViewController:toViewController:duration:options:animations:completion:
These functions became available in iOS 5. I should have properly read through all the new iOS 5 features first.

Related

"Warp" to a view iPhone iOS

I am currently developing an App based on a Navigation Controller. However, when the user logs out, I'd like to go to the initial screen and destroy all of the other views that were stacked. What is the best way to do that?
EDIT:
I've tried doing what both answers suggested but I got a nil navigationViewController. So I'll add another detail that I thought was not useful before. Actually I am trying to perform this operation from a TabViewController that is embedded in a NavigationController. I apologize if that changes anything.
[self.navigationController popToRootViewControllerAnimated:YES];
Send a popToRootViewControllerAnimated message to the navigation controller

popViewController / viewWillAppear not animated in iOS 5

I wasn't lucky with searching for this, so here we go ;)
I have a UIViewController with a custom UINavigationBar which pushes another UIViewController as subview.
Everything works fine except when I click the back button on the subview. The previews (first) view appears correctly, but not animated. The animation of the UINavigationBar is correct, only the views switch immediately.
The function - (void)viewWillAppear:(BOOL)animated of the first UIViewController gets called with NO for animated. This only happens when I test with iOS 5, not with iOS 4.
Does anyone know how to fix this?
Thanks for your help! Hannes
UPDATE 1
I just removed all custom code and just used the plain UINavigationBar (so no extra settings) and it still doesn't work with iOS 5. This is my code I use in the first ViewController to push the second ViewController:
[self.navigationController pushViewController:secondViewController animated:YES];
As I already mentioned - when I click the back button in the navigation bar on the second view the first view appears immediately without animation.
Any help would be appreciated! Thanks!
UPDATE 2
I feel like I'm getting closer to the issue, but still no solution:
I just added a custom UINavigationController where I just call [super popViewControllerAnimated:animated]. This get's called correctly (animated is YES) but the viewWillAppear of the first UIViewController gets NO as value for animated...
I was having a similar problem today where the UIViewController was getting NO in viewWillAppear, except with the standard UINavigationBar and UINavigationController.
It turned out to be due to manually calling viewWillAppear:YES somewhere it shouldn't have been. This item suggests that it can also be caused by calling the wrong super method somewhere (e.g. [super viewWillAppear:animated] instead of [super viewDidAppear:animated] inside of viewDidAppear).
As for using a custom UINavigationBar, I ran across this link today that may help your case: http://sloshire1.posterous.com/simple-fix-for-viewwillappear-in-ios5
Apple implemented official ways to create custom navigation bars in iOS 5. Unfortunately, they also broke most of the non-official ways of doing it in iOS 4. iOS 5 won't call drawRect for you anymore. You need to have two ways of doing it, one for iOS 5 and greater, using the new calls, and one for iOS 4 and earlier, using the old calls. Check out the documentation for custom navigation bars in iOS 5 for more info.
Did you try to remove all your custom code and go with the native navigation bar? Does the behavior stay the same? This way you can check if your custom bar messes with the transition.

How To Create Multiple Views Without A Navigation Controller?

I am trying to create multiple views in my view-based iPhone app in Xcode 4. I have followed many tutorials and read many articles but none of them have worked. I figured out that they require a Navigation Controller. How can I create 2 views that are switched with a button without a Navigation Controller?
Thanks!
I would use presentModalViewController. There are a ton of youtube videos on how to switch views, some of them don't have presentModalViewController so you have to watch the video to see if they write presentModalViewController in their code. I always use presentModalViewController.
you can create one additional view and keep it as a retained variable in your controller and on demand, you can do
[self.view addSubview:secondView];
//or - to remove second view and show first view
[secondView removeFromSuperView];
Why not use a UINavigationController but disable the navigation bar?
It's the easiest way to do it. And it will avoid many issues that can come about with incorrect view controller programming. Your users will never know the difference - there are no visual clues that you've done it that way.

Two Views in 1 view controller

Basically, what I am trying to do is I have my TestViewController and there are 2 views under it, the first view will start with a tool bar and 2 buttons, one for imagepicker and the other one for mail sending, I am already done with that, and after pick the image from the photo library, the second view will be popped out(I want to do some image editing here) with a tool bar and 1 button back to the first view. I am doing something like [self.view addSubview:2ndview], and it works, but when I am trying to use -(IBAction)dismissDrawing:{[2ndview removeFromSuperview] }the program just shut down.
Can anyone help me? Really appreciate your help!
Look at my sample application I did last year. Basically you need a view that will act like a superview, then add views on top of it (if I remember correctly, it's been a while since I did it that way, now I just use multiple xibs).
It sounds like what you're trying to do would be better suited to a modal view.
See Human Interface Guidelines - Modal Views
Instead of adding a subview, try
[self presentModalViewController:secondView animated:YES];
Then in the dismissDrawing you can use
[self dismissModalViewControllerAnimated:YES];

pushView - set Longger time - iPhone

I have following code in my application.
[self.navigationController pushViewController:x animated:YES];
It will push a new view to the application.
I want to change the animation time for pushing.
What should I Do?
You can't use the built-in UINavigationController Animation to accomplish this. It isn't customizable.
You will instead have to create your own animation, like with a CATransition. Then you can configure all of the attributes.
The only problem will be the navigation bar. You will have to handle that as well.
Also you will have to get the navigation hierarchy correct. You may have to be creative to get this right.