想要实现类似Facebook和许多其他应用程序中使用的视图控制器转换,已附上快照。这是否需要使用CoreAnimation框架或者在工具包中可用?
想要实现类似Facebook和许多其他应用程序中使用的视图控制器转换,已附上快照。这是否需要使用CoreAnimation框架或者在工具包中可用?
除非你想导入一个第三方框架,否则你必须使用CoreAnimation,但是使用CoreAnimation非常简单,我建议你学习它,因为它非常强大。这里是最简单的方法,以便让你有一个想法。一旦你掌握了它,你可以自己更好地调整它来适应你的需求:
在你的视图控制器中有两个视图:
@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!
}
-(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];
}
看一下这个,它可能会给你一个起点: https://github.com/Inferis/ViewDeck/