Fir*_*ous 6 core-animation uiviewcontroller uiviewanimationtransition ios ios5
想要实现类似于在facebook和许多其他应用程序中使用的视图控制器转换,附加快照.它需要使用CoreAnimation框架还是可以在工具包中使用?

你必须使用CoreAnimation,除非你想导入别人建议的第三部分框架,但是使用CoreAnimation非常简单,我建议你学习它,因为它非常强大。这是为您提供想法的最简单的方法。一旦掌握了它的窍门,您就可以自己更好地构造它,以满足您的需求:
在你的视图控制器中有 2 个视图:
@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!
}
Run Code Online (Sandbox Code Playgroud)
在界面生成器中创建它们,或者通过代码或者您习惯的方式创建它们。让它们互相重叠,这样你就只能看到 topView,而让 buttomView 留在它后面。
当用户按下按钮显示菜单时:
-(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];
}
Run Code Online (Sandbox Code Playgroud)
当然,您应该为“facebook视图”和“菜单视图”等实现您自己的UIView子类,并在上面的示例中用于topView和bottomView。