xcode 带有故事板的幻灯片菜单 ios 7
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24736687/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Slide menu with storyboards ios 7
提问by LS_
I need to implement on my app a Slide menu (like the one on the facebook app) but i also wants to have buttons on my Views that links to other Views, for example on my Main View I have a button that on click goes to OptionView but i also want to have a slide menu That links to OptionView, i'm using storyboards and xcode 5 and I wanted to know if someone can help me to figure out how to create the Slide menu
我需要在我的应用程序上实现一个幻灯片菜单(就像 facebook 应用程序上的那个),但我也想在我的视图上有链接到其他视图的按钮,例如在我的主视图上我有一个按钮,点击后会转到OptionView 但我也想有一个链接到 OptionView 的幻灯片菜单,我正在使用故事板和 xcode 5,我想知道是否有人可以帮助我弄清楚如何创建幻灯片菜单
采纳答案by Gal Marom
You can either use this to have an idea / use the open source: https://github.com/aryaxt/iOS-Slide-Menu
您可以使用它来获得想法/使用开源:https: //github.com/aryaxt/iOS-Slide-Menu
or you can implement it like this:
或者你可以像这样实现它:
Add to your navigation bar a UIBarButtonItem
:
添加到您的导航栏 a UIBarButtonItem
:
UIBarButtonItem *rightRevealButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"reveal-icon.png"] style:UIBarButtonItemStyleBordered target: self action:@selector(rightRevealToggle:)];
self.navigationItem.rightBarButtonItem = rightRevealButtonItem;
implement the rightRevealToggle
:
实施rightRevealToggle
:
- (void)rightRevealToggle:(id)sender
{
float width = self.view.frame.size.width;
float height = self.view.frame.size.height;
self.navigationItem.rightBarButtonItem.enabled = FALSE;
CGRect rearViewFrame = _rearViewController.view.frame;
float deltaToMoveRearView = _rearViewController.datePicker.frame.size.width;//0.25f * width;
//slide the rear view inside
if(_rearViewController.view.hidden && ![sender isKindOfClass:[UISwipeGestureRecognizer class]])
{
_rearViewController.view.hidden = FALSE;
[UIView animateWithDuration:0.7f animations:^{
_rearViewController.view.frame = CGRectMake(width - deltaToMoveRearView,rearViewFrame.origin.y,rearViewFrame.size.width,rearViewFrame.size.height);
_contentViewController.view.frame = CGRectMake(-deltaToMoveRearView , 0, width, _contentViewController.view.frame.size.height);
NSLog(@"3: frame: x:%f y:%f",_contentViewController.view.frame.origin.x,_contentViewController.view.frame.origin.y);
} completion:^(BOOL finished){
self.navigationItem.rightBarButtonItem.enabled = TRUE;
}];
}
//slide the rear view outside
else
{
self.rearViewController.view.hidden = FALSE;
[UIView animateWithDuration:0.7f animations:^{
_rearViewController.view.frame = CGRectMake(width,rearViewFrame.origin.y,rearViewFrame.size.width,rearViewFrame.size.height);
_contentViewController.view.frame = CGRectMake(0, 0, width, _contentViewController.view.frame.size.height);
self.titleLabel.alpha = 1;
} completion:^(BOOL finished){
_rearViewController.view.hidden = finished;
self.navigationItem.rightBarButtonItem.enabled = TRUE;
}];
[self updateContentViewController];
}
}
- (void)updateContentViewController
{
UIViewController *newVC = [self.storyboard instantiateViewControllerWithIdentifier:[NSString stringWithFormat:@"%@VC",_rearViewController.selectedSection]];
if([newVC class] == [ScoresViewController class])
{
if([_contentViewController class] == [ScoresViewController class] &&
[((ScoresViewController *) _contentViewController) date] != _rearViewController.datePicker.date)
{
((ScoresViewController *) newVC).date = _rearViewController.datePicker.date;
[self cycleToViewController:newVC];
}
}
if([newVC class] != [_contentViewController class])
{
[self cycleToViewController:newVC];
}
}