我如何在 xcode iphone 中创建一个滑动菜单,就像主 android 菜单滑动菜单一样?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6872407/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 21:36:21  来源:igfitidea点击:

how do i create a sliding menu in xcode iphone like the main android menu sliding menu?

iphonexcodecocoa-touch

提问by phil

ive been looking all over the web for an example of a sliding menu described in the title. All i need is to know what item from the iphone library i should be looking at to make this, i dont want to take up somebodys time making them write out the code but a little direction will be appreciated?

我一直在网上寻找标题中描述的滑动菜单示例。我所需要的只是知道我应该查看 iphone 库中的什么项目来制作这个,我不想占用某人的时间让他们写出代码,但会有一点方向吗?

采纳答案by Pravara Patil

we have created a sliding drawer in our iphone application, we have done this using following procedure:

我们在我们的 iphone 应用程序中创建了一个滑动抽屉,我们使用以下程序完成了此操作:

  1. Create a UIView object in your View Controller in Interface builder.
  2. create the object of UIView in your view controller (do not forget to make it (IBOutlet) in .h file)
  3. Similarly create a button in both interface builder and view controller, along with it's action method.
  4. Link the objects in header file with objects in interface builder
  1. 在界面构建器的视图控制器中创建一个 UIView 对象。
  2. 在视图控制器中创建 UIView 对象(不要忘记在 .h 文件中创建它(IBOutlet))
  3. 同样在界面构建器和视图控制器中创建一个按钮,以及它的操作方法。
  4. 将头文件中的对象与界面构建器中的对象链接起来

In viewDidLoad of your view controller set frame of the view you want to slide, with button

在视图控制器的 viewDidLoad 中设置要滑动的视图的框架,带有按钮

    - (void)viewDidLoad {
[super viewDidLoad];

toOpenView.frame = CGRectMake(self.view.frame.size.width, toOpenView.frame.origin.y, 0, toOpenView.frame.size.height);

}

}

In click event of your button add following code

在按钮的单击事件中添加以下代码

    -(IBAction)onOpenButtonClick:(id)sender
    {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.8];

if (toOpenView.frame.origin.x == self.view.frame.size.width/2)
{

    toOpenView.frame = CGRectMake(self.view.frame.size.width, toOpenView.frame.origin.y, 0, toOpenView.frame.size.height);
    openButton.frame = CGRectMake((self.view.frame.size.width - openButton.frame.size.width), openButton.frame.origin.y, openButton.frame.size.width, openButton.frame.size.height);

}
else
{
    toOpenView.frame = CGRectMake(self.view.frame.size.width/2, toOpenView.frame.origin.y, self.view.frame.size.width/2, toOpenView.frame.size.height);
    openButton.frame = CGRectMake((toOpenView.frame.size.width - openButton.frame.size.width), openButton.frame.origin.y, openButton.frame.size.width, openButton.frame.size.height);
}
[UIView commitAnimations];

}

}

回答by Praveen S

Thiswil help you get started hopefully.

将有希望地帮助您开始。