2

This question gives a basic description of what I'm trying to do. Basically, I am animating offscreen content into view. There are several subviews I animate in this way, but they never occupy the same space at the same time. Now I'm having trouble being able to design content that starts offscreen. I have tried two ways, neither satisfactory:

  1. I stacked the subviews on top of each other where they will be viewed, and set the position to offscreen in the User Defined Runtime Attributes. I don't like this way, because I can't easily toggle which view I'm looking at, so designing is tough.
  2. I initially positioned the subviews off screen. This is annoying because you have to reposition a subview back onscreen before you can see it to design it.

How would this be done? How have you done accomplished something similar in the past?

Community
  • 1
  • 1
benekastah
  • 5,651
  • 1
  • 35
  • 50

1 Answers1

1

I'm not quite sure I'm getting it but I'll take a shot here.

So in storyboard you can create a view that is not connected or segued to the root view - you just drag out a viewController object from the libray and design it as you want. It doesn't have to be on top of anything or contained within the root viewController view.

Once you have this you can instantiate it when you need to with:

[[UIStoryboard storyboardWithName:@"MainStoryboard_iPad" bundle:NULL] instantiateViewControllerWithIdentifier:@"someName"];

From there you can position it and set up a UIView animation to bring it into view.

Or maybe I am not getting it...

EDIT (fixed error):

myViewController = [[UIStoryboard storyboardWithName:@"MainStoryboard_iPad" bundle:NULL] instantiateViewControllerWithIdentifier:@"someName"];

[self addChildViewController:myViewController];
[self.view addSubview:myViewController.view];

//do the animation on screen
benekastah
  • 5,651
  • 1
  • 35
  • 50
spring
  • 18,009
  • 15
  • 80
  • 160
  • This would be an ideal approach. The only question I have then is: is there a way to get the different views to animate in and out, while maintaining a fixed background image? – benekastah Mar 20 '12 at 05:57
  • Sure - when you instantiate a view you keep a reference to it and then you can control when it appears/disappears. Since these views are added to the main view subview, they will appear on top. See the edit above – spring Mar 20 '12 at 06:25
  • This is partially working for me. I'm trying to add the subview like this: `[self.view addSubview:myViewController.view]` since the first line you gave actually gives me a view controller. The problem is the view on the view controller isn't immediately available. I assume this is because `myViewController` hasn't loaded completely yet. How can I defer an action until `myViewController` has loaded completely? – benekastah Mar 21 '12 at 02:53
  • Edited question to include solution to my view problem mentioned above (won't be visible until peer reviewed). – benekastah Mar 21 '12 at 15:52
  • What if you're just trying to get ONE of the subviews in the second view controller to show up - not the whole thing? – Tommy Nicholas Dec 20 '13 at 00:29