如何Facebook风格过渡 [英] How to facebook style transition

查看:84
本文介绍了如何Facebook风格过渡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想要实现类似于在facebook和许多其他应用中使用的视图控制器转换,附加了快照。它需要使用CoreAnimation框架还是可以在工具包中使用?

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

推荐答案

除非要导入第三方框架,否则必须使用CoreAnimation有人建议,但使用CoreAnimation非常简单,我建议你学习它,因为它非常强大。这是最简单的方法,可以给你一个想法。一旦你掌握了它,就可以自己构建一下它,以满足你的需求:

You have to use CoreAnimation unless you want to import a 3rd part framework that someone suggested, but it is very simple to use CoreAnimation and I suggest you learn it because it is very powerful. Here is the simplest approach possible to give you an idea. You could structure it a little better yourself once you get a hang of it, to fit your needs:

在你的viewcontroller中有2个视图:

In your viewcontroller have 2 views:

@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!
}

在界面构建器中创建它们,或者通过代码创建它们,或者您已经习惯了。让它们相互重叠,这样你只能看到topView,并让buttomView留在它后面。

Create them in interface builder, or by code or however you are used to. Make them overlap eachother so that you only see the topView, and let the buttomView stay behind it.

当用户按下按钮显示菜单时:

When the user presses the button to show 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];
}

当然,你应该为facebook view实现自己的UIView子类以及菜单视图等,并在上面的示例中用于topView和bottomView。

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

这篇关于如何Facebook风格过渡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆