我需要在我的应用程序上实现一个幻灯片菜单(就像Facebook应用程序上的那个)但我也希望我的视图上有按钮链接到其他视图,例如在我的主视图上我有一个按钮,点击进入OptionView,但我也希望有一个幻灯片菜单链接到OptionView,我使用故事板和xcode 5,我想知道是否有人可以帮我弄清楚如何创建幻灯片菜单
答案 0 :(得分:1)
您可以使用它来了解/使用开源: https://github.com/aryaxt/iOS-Slide-Menu
或者您可以像这样实现它:
将UIBarButtonItem
:
UIBarButtonItem *rightRevealButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"reveal-icon.png"] style:UIBarButtonItemStyleBordered target: self action:@selector(rightRevealToggle:)];
self.navigationItem.rightBarButtonItem = rightRevealButtonItem;
实施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];
}
}
答案 1 :(得分:1)
通过以下链接查看以下链接