像iOS 6,7兼容的图像中显示的菜单

时间:2014-03-31 06:50:35

标签: ios menu slide

我需要一张与iOS 6和iOS 7兼容的图片中提到的滑动菜单

enter image description here

2 个答案:

答案 0 :(得分:0)

您可以查看this tutorial。它将告诉你如何在手机的两侧执行此操作。

如果你不想阅读所有这些:

主要思想是在主视图下面有一个视图。当您滑动或触摸菜单按钮时,您只需通过执行以下操作移动顶视图(我在所有视图控制器继承的类上执行此操作,但您可以随意在任何需要/需要它的位置执行此操作):

// self.isMenuOpened is a flag to save menu state and set the move distance (and a few other things)

// Init move distance
float move = 270; // 270 is arbitrary value, you can set it as you like
if (self.isMenuOpened) { move = -move; }

// Moves all view except menu
[UIView beginAnimations:@"openMenu" context:nil];
[UIView setAnimationDuration:kAnimationDurationShort];

// Navigation bar frame moving (if you have one)
CGRect navFrame = self.navigationController.navigationBar.frame;
self.navigationController.navigationBar.frame = CGRectMake(navFrame.origin.x + move,
                                                           navFrame.origin.y,
                                                           navFrame.size.width,
                                                           navFrame.size.height);

// Call switching move on each view
BOOL first = true;
for (UIView *view in [self.view subviews]) {

    if (first) { first = false; } // First view is menu if it's on minimum zIndex
    else {
        CGRect mainViewFrame = view.frame;
        [view setUserInteractionEnabled:self.isMenuOpened]; // Disable your main view as it still visible
        view.frame = CGRectMake(mainViewFrame.origin.x + move, mainViewFrame.origin.y,
                                mainViewFrame.size.width, mainViewFrame.size.height);

    }
}


[UIView commitAnimations];

我遍历所有子视图,因为在少数情况下,我添加了一两个视图。但是如果您有一个视图(然后是下面的菜单),则不必执行所有迭代操作。希望有所帮助!

答案 1 :(得分:0)

您可以使用这个非常棒的简单库

https://github.com/arturdev/AMSlideMenu

支持左右菜单和完全自定义