2

I have a method that loads a nib file containing a view:

[[NSBundle mainBundle] loadNibNamed:@"NewView" owner:self options:nil]; 

and I was wondering if it's possible to add a simple transition when the view loads. I have scoured the internet and I haven't been able to find anything.

bryanmac
  • 38,941
  • 11
  • 91
  • 99

1 Answers1

3

There are many ways to present views and animate them.

You can create create using loadNibnamed:

How to load a UIView using a nib file created with Interface Builder

One way to animate a view in is to present it modally. This will animate from the bottom:

[[self navigationController] presentModalViewController:navController animated:YES];

These posts show getting more control how it animates in using modalTransitionStyle

How can I change the animation style of a modal UIViewController?

iPhone - presentModalViewController with transition from right

Another option is to create a view, add it as a subView to your current view and animate the frame. If you're just loading a view, consider using UINib - it was added in iOS 4.0 and caches. It double perf.

UINib *nib = [UINib nibWithNibName:@"TestView" bundle:nil];
UIView *myView = [[nib instantiateWithOwner:self options:nil] objectAtIndex:0]];

Then, you can add it as a subView.

If you want to animate subViews within your view, see this tutorial:

http://www.raywenderlich.com/2454/how-to-use-uiview-animation-tutorial

Specifically:

CGRect basketTopFrame = basketTop.frame;
basketTopFrame.origin.y = -basketTopFrame.size.height;

CGRect basketBottomFrame = basketBottom.frame;
basketBottomFrame.origin.y = self.view.bounds.size.height;

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelay:1.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

basketTop.frame = basketTopFrame;
basketBottom.frame = basketBottomFrame;

[UIView commitAnimations];
Community
  • 1
  • 1
bryanmac
  • 38,941
  • 11
  • 91
  • 99