【问题标题】:like menu shown in image with iOS 6,7 compatible与 iOS 6,7 兼容的图像中显示的类似菜单
【发布时间】:2014-05-10 09:55:34
【问题描述】:

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

【问题讨论】:

标签: ios menu slide


【解决方案1】:

您可以查看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];

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

【讨论】:

    【解决方案2】:

    您可以使用这个很棒且简单的库

    https://github.com/arturdev/AMSlideMenu

    支持左右菜单,完全可自定义

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-22
      • 1970-01-01
      • 1970-01-01
      • 2021-05-14
      • 1970-01-01
      • 2014-11-26
      • 2012-08-18
      • 1970-01-01
      相关资源
      最近更新 更多