Tom
Tom

Reputation: 65

UiView Transition inside UIView

this feels like a beginner question, but since I am not able to get it working in the intended-fashion, I am hoping somewhere out there is able to point me in the right direction.

What I am trying to achive is a transition of a view inside a view. I fundamentally want to replace a view inside a view with another view(controller?!?) 's content.

lets say, I have an image of a book and I want to do a transition inside the book to another page (going from the calendar-view to the detailed daily view for example). I only want the "book-content"(white content area) to be included in that transition, and not the whole book itself(whole screen).

I can do a transition with the same view, no problem, but I dont get it working trying to replace the view with a completly different view. It didnt matter having the views in seperate viewcontrollers, or all the views in one viewcontroller, so I were not able to get it working yet, but even worse, I am running out of ideas. So HELP! If please somebody out there could be so kind and tell me what I am doing wrong. Suggestions also very much appreciated. Thanks!!

Tom

Upvotes: 2

Views: 6845

Answers (3)

sudo rm -rf
sudo rm -rf

Reputation: 29524

Maybe you could hide one view then show the other using a UIView Animations block.

[UIView beginAnimations:nil context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:view1.view cache:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:view2.view cache:YES];
[UIView setAnimationDuration: 1.5];
[UIView commitAnimations];

view1.view.hidden = YES;
view2.view.hidden = NO;

Edit: Is this what you were looking for?

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
[view1 viewWillDisappear:YES];
[view2 viewWillAppear:YES];

view1.view.hidden = YES;
view2.view.hidden = NO;
[view1 viewDidDisappear:YES];
[view2 viewDidAppear:YES];
[UIView commitAnimations];

Or, you could use something like this:

[UIView animateWithDuration:0.5
                  delay:0.0 
                options:UIViewAnimationOptionTransitionFlipFromRight 
             animations:^{
                             [view1 removeFromSuperview];
                             [mySuperview addSubview:view2]; 
                         }
             completion:nil];

Upvotes: 3

user189804
user189804

Reputation:

Suppose you have a view controller with two views, A and B. They have identical frames so they occupy the same space in the controller's view, for your purposes displaying a page of a book. You want to display one and transition to the other.

One way would be to set the alpha property of one to 1.0 (opaque) and the other to 0.0 (transparent). Because this property can be animated you could do a fade from one to the other using a beginAnimations:context/commitAnimations, or use one of the block methods like the docs advise.

Another way would be to animate a change in frame in the two views. Set up the views so that one has a frame such that it is in the right place to display, the other has the same frame but with frame.origin.x equal to frame.size.width - it will be hidden because it is off-screen or hidden behind some other view. Animate the frame in by setting view A's frame.origin.x to -frame.size.width and frame B's frame.origin.x to the display position x origin. Then set (no animation) frame A's frame.origin.x to frame.origin.width again, update its content and you are ready to slide another page in from the right.

Upvotes: 0

GendoIkari
GendoIkari

Reputation: 11914

Check out the exchangeSubviewsAtIndex: method in the UIView class. Just set up the 2 views that you want to transition from and to as subviews of another view; then call this method on that parent view.

Upvotes: 1

Related Questions