How to go in facebook style

Want to implement a view controller transition similar to that used in facebook and in many other applications, a snapshot is attached. Will it require a game with a CoreAnimation framework or is it available in the toolbox?

enter image description here

+6
source share
2 answers

You should use CoreAnimation if you do not want to import the third part framework that someone suggested, but it is very simple to use CoreAnimation, and I suggest you study it because it is very powerful. Here is a simple way that can give you an idea. You can create it a little better as soon as you can get it to fit your needs:

There are 2 types in your viewcontroller:

@interface yourViewController : UIViewController { // The facebook view in the example, this will be the view that moves. // Init this view with x=0 and let it cover the whole screen. IBOutlet UIView *topView; // The fb menu in the example // Init this view so that it stays behind the topView. IBOutlet UIView *bottomView; BOOL menuVisible; // init to false in viewDidLoad! } 

Create them in the interface builder, either using code or, as you are used to. Make them coincide with each other, so that you only see the top screen and let buttomView remain behind it.

When the user clicks a button to display the menu:

 -(IBAction)menuButtonPressed:(id)sender { // Set up animation with duration 0.5 seconds [UIView beginAnimations:@"ToggleMenu" context:nil]; [UIView setAnimationDuration:0.5]; // Alter position of topView CGRect frame = topView.frame; if (menuVisible) { frame.origin.x = 0; menuVisible = NO; } else { frame.origin.x = 300; //Play with this value menuVisible = YES; } topView.frame = frame; // Run animation [UIView commitAnimations]; } 

Of course, you must implement your own UIView subclasses for "browsing facebook" and "menu view", etc. and use for topView and bottomView in the above example.

+4
source

Take a look at this, this can give you a starting point: https://github.com/Inferis/ViewDeck/

+1
source

Source: https://habr.com/ru/post/920224/


All Articles