创建从底部向上滚动的菜单的最佳方法?

发布于 2025-01-07 14:09:00 字数 269 浏览 0 评论 0原文

我对 iPhone 编程相当陌生,我正在制作一个相当基本的应用程序。无论如何,我只想知道如何创建一个从底部(从选项卡栏顶部开始)向上滚动的菜单,显示一些选项。我附上了一张图片,可以更好地描述我的意思。我假设我应该创建某种子视图,然后向其中添加一些动画,但我想获得您关于最佳开始方式的建议。 谢谢

主屏幕 菜单

I'm fairly new to iPhone programming, and I'm making a fairly basic app. Anyway, I just want to know how to go about creating a menu that scrolls up from the bottom (beginning at the top of the tab bar) that displays a few options. I've attached a picture that better helps portray what I mean. I'm assuming I should create some sort of subview and then add some animation to it, but I'd like to get your advice on the best way to start.
Thanks

Home Screen
Menu

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

已下线请稍等 2025-01-14 14:09:00

最简单的解决方案是使用未修改的 UIActionSheet。

如果这不是您想要的,那么使用模态视图控制器始终是一个选择。

但是,如果您想要的东西不会覆盖整个屏幕,并且可以具有自定义外观,则基本思想是这样的:

  1. 使用位于主视图底部的框架(例如,在 0,406 处)创建视图。
  2. 可以选择禁用用户与主视图的交互
  3. 使用 UIView 动画将其向上移动

代码如下所示:

UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height, self.view.bounds.size.width, kCustomViewHeight)];
[self.view addSubview:customView];

[UIView animateWithDuration:0.2 animations:^{
  CGRect f = customView.frame;
  f.origin.y -= kCustomViewHeight;
  customView.frame = f;
}];

The simplest solution would be to use a UIActionSheet, unmodified.

If that's not what you're looking for, using a modal view controller is always an option.

If, however, you want something that won't cover the entire screen, and can have a custom look, the basic idea is this:

  1. Create your view with a frame that's just at the bottom of your main view (e.g. at 0,406).
  2. Optionally disable user interaction with the main view
  3. Use UIView animations to move it up

The code would look something like this:

UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height, self.view.bounds.size.width, kCustomViewHeight)];
[self.view addSubview:customView];

[UIView animateWithDuration:0.2 animations:^{
  CGRect f = customView.frame;
  f.origin.y -= kCustomViewHeight;
  customView.frame = f;
}];
一杆小烟枪 2025-01-14 14:09:00

我自己没有这样做,但看到了一个很酷的源代码,它是在 UIScrollView 的帮助下执行的(默认情况下位于屏幕“下方”),包含 UITableView 和一个按钮(显示在屏幕底部)屏幕)。按下此按钮后,ScrollView 收到移动命令(在其 IBAction 中)。
篇幅较短,尝试看看 UIScrollView(在其中玩一下 UITableView)。

I didn't do it myself, but saw a cool source-code, where it was performed with the helped of UIScrollView (by default positioned "below" the screen), containing UITableView and a button (wich was shown at the bottom of the screen). ScrollView was getting a command to move after the press of this button (in IBAction of it).
Being shorter, try to look at UIScrollView (play with UITableView in it).

眼眸里的快感 2025-01-14 14:09:00

我做了类似的事情,通过子类化 UIActionSheet 并将我自己的控件添加为子视图,从屏幕底部弹出一些对象。我想在您的情况下可以使用类似的方法。

创建实现 UITableViewDelegateUITableViewDataSource 协议的 UIActionSheet 子类。在该类的 - (id)init 方法中,添加一个 UITableView 作为子视图,并以 self 作为委托和数据源。

然后从主视图中,使用 showInView: 调用自定义 UIActionSheet。

使用委托回调主视图,让它知道用户何时选择一个选项,然后使用 [myCustomMenu DismissWithClickedButtonIndex:0animated:YES] 隐藏菜单。

I've done something similar, popping up some object from the bottom of the screen by subclassing UIActionSheet and adding my own controls as subviews. I imagine a similar method could be used in your situation.

Create a subclass of UIActionSheet implementing the UITableViewDelegate and UITableViewDataSource protocols. In the - (id)init method of that class, add a UITableView as a subview with self as the delegate and data source.

Then from the main view, call your custom UIActionSheet with showInView:.

Use delegates to call back to the main view to let it know when the user selects an option, then use [myCustomMenu dismissWithClickedButtonIndex:0 animated:YES] to hide the menu.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文