Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use a CATransition, along these lines:</p> <pre><code>// Get index of view to be removed (oldSubView) NSUInteger index; for(index = 0; [subViews objectAtIndex:index] != oldSubView; ++index) {} // Remove old view [oldSubView removeFromSuperview]; // Inser new view at right index [self insertSubview:newSubView atIndex:index]; // Create the transition CATransition *animation = [CATransition animation]; [animation setDelegate:self]; [animation setType:kCATransitionPush]; [animation setSubtype:kCATransitionFromLeft;]; [animation setDuration:0.5f]; [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; [[self layer] addAnimation:animation forKey:@"pushIn"]; </code></pre> <p>You don't have to tell the transition which views to push, it will do it automatically (since you removed and inserted views).</p> <p>Have a look at this example code from Apple: <a href="http://developer.apple.com/iphone/library/samplecode/ViewTransitions/" rel="nofollow noreferrer">how to perform transitions between two views using built-in Core Animation transitions</a>.</p> <p>EDIT (in response to comments): This code should be used inside a UIView subclass. If you want to use it in a UIViewController subclass, you have to change self to self.view everywhere. You would simply put this code into a separate method with a signature like this:</p> <pre><code>-(void)replaceView:(UIView*)oldSubView withView:(UIView*)newSubView; </code></pre> <p>You put that method into your class, and call it whenever you want to replace one view with another. You need to have a reference to these views, obviously.</p> <p>My best guess is that you should replace this code:</p> <pre><code>[self.view addSubview:[self.FreebiesViewMainObject view]]; [self BringSubviewsToFront]; </code></pre> <p>with</p> <pre><code>[self replaceView:self.rootView withView:freebiesViewMainObject.view]; </code></pre> <p>But you have to work on this a bit more to get all the pieces to fit together. Really, looking at some good example code like the one I linked to, and really <em>understanding</em> it, is a lot better then to get a few code snippets off of SO and try to throw them into your code.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload