How to use UIView's UIViewAnimationCurveEaseIn in iOS? - ios

I'm trying to add subview with UIViewAnimationCurveEaseIn into MyMainView.
I have two UIView in my ViewController.xib file.
There is a one button in MainView , when I clicked that button, I want to call another view with UIViewAnimationCurveEaseIn.
In some of iOS app, the new view appear from the below with slide.
I think that's used with UIViewAnimationCurveEaseIn.
I also want to do like that.
If I'm wrong,please guide me how to do that.
Or where can I read that function?

Try this:
AViewController *aVC = [[AViewController alloc]initWithNibName:#"AViewController" bundle:nil];
//[self.navigationController pushViewController:aVC animated:NO];
[UIView transitionFromView:self.view toView:aVC.view duration:0.5f options:UIViewAnimationCurveEaseIn completion:^(BOOL doneDissolve){
[self.view addSubview:aVC.view];
}];
[aVC release];

Related

How could I present a viewController while still see the background viewController

The Photo Sharing part is a ViewController I wrote, when I press the right item, the PhotoSharingViewController will appear animatedly.
Here is my code:
PhotoSharingViewController *vc = [[PhotoSharingViewController alloc] init];
[self addChildViewController:vc];
[self.view addSubview:vc.view];
[UIView animateWithDuration:0.3 animations:^{
vc.view.frame = CGRectMake(0, 0, WIDTH, WIDTH * 0.8);
} completion:^(BOOL finished) {
}];
However, I do not think it is a good way. I prefer to "present" the viewController, like UIAlertController, or UIActivityViewController. How could I do that, please?
You want to provide a custom transition. That way, when presentViewController is called, you get to provide the UIPresentationController as well as the animation. You are in complete charge of both where the presented view goes and how it animates to get there.

change transition of navigationcontroller ios

In the typical viewcontroller transition both views, the disappear and appear view are moving, but now I want to create a custom animation where you throw the event to change of view, the view that will disappear, just hide without transition and animation, and the view will appear continue with the same transition.
then the problem here is I have navigation bar and I don't know, how can I create a custom transition of navigation bar?,
can you help me to know how to change or remove the transition of navigation controller.
I've try it but it only add other transition and don't remove the base transition.
For Push:
MainView *nextView = [[MainView alloc] init];
[UIView animateWithDuration:0.75
animations:^{
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[self.navigationController pushViewController:nextView animated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
}];
For Pop:
[UIView animateWithDuration:0.75
animations:^{
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:transition forView:self.navigationController.view cache:NO];
}];
[self.navigationController popViewControllerAnimated:NO];
any ideas? thanks :D
You can just use add as subview and have title bar to mimic like navigation controller.
MainView *nextView = [[MainView alloc] init];
//setup frame
nextView.view.frame = xxx;
[self.view addSubview:nextView.view];
Remove using [nexView.view removeFromSuperView];
OR
Just add some view above your current view with default hidden and set hidden NO on some action or call bringSubviewFront method if you want to keep view below and bring in front on some action.

How to show UIViewController in other UIViewController?

This is typical question and possibly duplicated, but..
There is iPad app which has UINavigationBar and UITabBar. I have created a button on navigationBar which must show appinfoViewController.
When I present it navigationBar and tabTab are still available to tap. But I would like to show appinfoViewController to full app's main screen size (like modal)
This is my code:
- (void)showInfo
{
AboutViewController *about = [[AboutViewController alloc] init];
[about.view setFrame: self.view.frame];
[about.view setAlpha:0.0];
[UIView animateWithDuration:0.5
delay:0.0
options: UIViewAnimationOptionCurveLinear
animations:^{
[about.view setAlpha:1.0];
[self.view addSubview:about.view];
[self addChildViewController:about];
[about didMoveToParentViewController:self];
}
completion:^(BOOL finished){
}];
}
How to present appinfoViewController to full screen?
May be it's possible to present it modally but without BLACK background?
As suggested in the comments, using
[self presentViewController:about animated:YES completion:nil]
would get rid of the nav bar and the tab bar. If you need to keep them, you need to use
[self.navigationController pushViewController:about animated:YES];
EDIT:
In order to have the user interaction disabled everywhere except for your about view, it's slightly trickier: first off, you need to have all of your UI elements embedded in a view that is not the main view of your presenting view controller.
Let's say you have only a button (the "show about" button), you wouldn't just place it in your main view, but you would use another view (let's call it "outer view") that is just as big as the view controller's view and where you place the button (along with any other ui element you might have). You also need an outlet to this outer view. Then write a method such as:
-(void)userInteractionEnabled:(BOOL)enabled
{
self.navigationController.navigationBar.userInteractionEnabled = enabled;
self.tabBarController.tabBar.userInteractionEnabled = enabled;
self.outerView.userInteractionEnabled = enabled;
}
Alternatively you could simply disable every "interactive" outlet instead of outerView. So if, for example, you have 2 textviews, 3 buttons and one UIPickerView, you would set userInteractionEnabled = enabled for each of those outlets (instead of doing it only for the parent view).
Now, in your showInfo method you can have:
CGRect frame = CGRectMake(50, 50, 200, 200); //Use whatever origin and size you need
about.view.frame = frame;
[self.view addSubview:about.view];
[self userInteractionEnabled:NO]
And in your btnClose method you can just put:
[about.view removeFromSuperview];
[self userInteractionEnabled:YES];
I hope this helps, let me know if this is what you needed!
P.S. Maybe you're already aware of this, but there is a class UIPopoverController, only available for iPad's apps, that would pretty much do all of this for you. You can find a tutorial on how to use it here.
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:nil];
AboutViewController *about = (AboutViewController *)[storyBoard instantiateViewControllerWithIdentifier:#"about"];
[self.navigationController pushViewController:about animated:YES];
You can add viewcontroller view layer directly to presenting viewcontroller view.
Code should be look like --
AboutViewController *about = [[AboutViewController alloc] init];
[about.view setFrame: self.view.bound];
[about.view setAlpha:0.0];
[self.view addSubview:about.view];
[UIView animateWithDuration:0.5
delay:0.0
options: UIViewAnimationOptionCurveLinear
animations:^{
[about.view setAlpha:1.0];
}
completion:^(BOOL finished){
}];

Use presentModalViewController but with modeUIViewAnimationTransitionCurlUp

How is it possible that I change the transition for presenting a modal view controller. Is it possible that the presenting transition is using the default UIModalTransitionStyle....
UIModalTransitionStyleCoverVertical = 0,
UIModalTransitionStyleFlipHorizontal,
UIModalTransitionStyleCrossDissolve,
UIModalTransitionStylePartialCurl,
but the dismiss transition is using the UIViewAnimationTransitionCurlUp transition. Important is that I don't want to use the UIModalTransitionStylePartialCurl it should be the CurlUp one.
Sadly the following code doesn't work:
[UIView transitionFromView:self.view toView:self.parentViewController.parentViewController.parentViewController.view duration:1.0 options:UIViewAnimationTransitionCurlUp completion:^(BOOL finished) {....}];
Maybe it has something to do that the view controller is displayed in modal mode.
It would be nice if someone can help.
It feels kludgy, but you can do this by animating the transition of adding your destination view controller's view, but on the completion of that, you immediately remove it again and then properly transition to it via the presentViewController (this time without animation, since the visual effect has already been rendered).
I do this in a subclassed custom UIStoryboardSegue (you didn't say NIBs or storyboard, but the concept is the same):
- (void)perform
{
UIViewController *src = self.sourceViewController;
UIViewController *dst = self.destinationViewController;
[UIView transitionWithView:src.navigationController.view
duration:0.75
options:UIViewAnimationOptionTransitionCurlUp | UIViewAnimationOptionCurveEaseInOut
animations:^{
[src.navigationController.view addSubview:dst.view];
}
completion:^(BOOL finished){
[dst.view removeFromSuperview];
[src presentViewController:dst animated:NO completion:nil];
}];
}
Clearly, if your source view controller doesn't have a navigation controller, you would replace those "src.navigationController.view" with just "src.view". But hopefully this gives you the idea.
And, anticipating the logical follow-up question, when dismissing the view controller, I have a button hooked up to an IBAction:
- (IBAction)doneButton:(id)sender
{
[UIView transitionWithView:self.view.superview
duration:0.75
options:UIViewAnimationOptionTransitionCurlDown
animations:^{
[self dismissViewControllerAnimated:NO completion:nil];
}
completion:nil];
}

How to present a UIViewController with an bottom-up animation without hiding TabBar

So, i have a UITabbarController with an UINavigationController in it. On the press of a button, i would like to bring in another UINavigationController, animating it like when using presentModalViewController:animated:, but i do not want it to hide the TabBar.
Is there anything in UIKit (3.1.3 and later) that i could use for this or will i have to do the animating myself?
Just test the code, maybe you need to set the navigationController as property if you need do sth like pushViewController:animated:.
UIViewController * aViewController = [[UIViewController alloc] init];
[aViewController.view setFrame:self.view.frame];
[aViewController.view setBackgroundColor:[UIColor redColor]];
UINavigationController * navigationController = [[UINavigationController alloc] initWithRootViewController:aViewController];
[aViewController release];
[navigationController.view setFrame:CGRectMake(0.0f, 480.0f, 320.0f, 480.0f)];
[self.navigationController.view addSubview:navigationController.view];
[UIView animateWithDuration:0.3f
delay:0.0f
options:UIViewAnimationOptionCurveLinear
animations:^{
[navigationController.view setFrame:CGRectMake(0.0f, 0.0f, 320.0f, 480.0f)];
}
completion:nil];
[navigationController release];
The only way by default to present something from the bottom up is the presentModalViewController. You can actually override the animations for your navigationController, but it isn't something you can achieve just by calling a different method, you will have to create your own, and handle the animations too.
Another way to possibly cheat this would be to reload your tabBar in the view you are presenting modally, but that could get messy.

Resources