如何实现类似的菜单视图? [iOS]

发布于 2024-11-27 03:38:13 字数 138 浏览 1 评论 0原文

有没有办法使用 sdk 轻松实现此菜单,还是必须手动制作(将覆盖视图和其他视图与按钮结合起来)?

在此处输入图像描述

提前致谢!

Is there a way to achieve this menu easily with the sdk or do I have to make it manually (combining an overlay view and other view with the buttons)?

enter image description here

Thanks in advance!

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

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

发布评论

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

评论(2

年少掌心 2024-12-04 03:38:13

这是标准 UIKit 框架中的 UIActionSheet 类

That's UIActionSheet class from standard UIKit framework

迷路的信 2024-12-04 03:38:13

来自 Apple 的 UIActionSheet 文档 由我进行了一些扩展,以触发呼叫操作。

在此处输入图像描述
ViewController 全局范围内的 Delcare:
UIActionSheet * actionSheet;UIView * yourView;

Int the viewDidLoad:

actionSheet = [[UIActionSheet alloc] initWithTitle:nil
                             delegate:self
                             cancelButtonTitle:@"Cancel"
                             destructiveButtonTitle:@"Delete Note"
                             otherButtonTitles:@"Call",@"Add a Contact",nil];

[yourView = self.view]

要通过某个带有 IBAction 声明的按钮来触发菜单,您将需要:

-(IBAction)viewMapButton:(id) sender
{
    [actionSheet showInView:yourView];

}

根据用户选择采取适当的操作声明以下方法并检查 [actionSheet buttonTitleAtIndex:buttonIndex] 等于什么:

- (void)actionSheet:(UIActionSheet *)actionSheet
        clickedButtonAtIndex:(NSInteger)buttonIndex
        {
        NSString * what_action = [actionSheet buttonTitleAtIndex:buttonIndex];
        NSLog(@"The %@ button was tapped.", what_action);
             if ([what_action isEqualToString:@"Call"])
                 {
                 NSString *phoneNumber = [[NSString alloc] 
                        initWithString:@"telprompt:1234567890"];
                 [[UIApplication sharedApplication] 
                        openURL:[NSURL URLWithString:phoneNumber]];
                 }
}

[注意:调用的触发在 iOS 模拟器上不起作用]

Easy example from Apple's documentation of UIActionSheet extended a bit by me to fire call action.

enter image description here
Delcare in the global scope of the ViewController:
UIActionSheet * actionSheet; and UIView * yourView;

Int the viewDidLoad:

actionSheet = [[UIActionSheet alloc] initWithTitle:nil
                             delegate:self
                             cancelButtonTitle:@"Cancel"
                             destructiveButtonTitle:@"Delete Note"
                             otherButtonTitles:@"Call",@"Add a Contact",nil];

[yourView = self.view]

To fire the menu by some declared button with IBAction you will need:

-(IBAction)viewMapButton:(id) sender
{
    [actionSheet showInView:yourView];

}

To take appropriate action depending on user choice declare following method and check what [actionSheet buttonTitleAtIndex:buttonIndex] was equal to:

- (void)actionSheet:(UIActionSheet *)actionSheet
        clickedButtonAtIndex:(NSInteger)buttonIndex
        {
        NSString * what_action = [actionSheet buttonTitleAtIndex:buttonIndex];
        NSLog(@"The %@ button was tapped.", what_action);
             if ([what_action isEqualToString:@"Call"])
                 {
                 NSString *phoneNumber = [[NSString alloc] 
                        initWithString:@"telprompt:1234567890"];
                 [[UIApplication sharedApplication] 
                        openURL:[NSURL URLWithString:phoneNumber]];
                 }
}

[NOTE: Firing of call does not work on iOS Simulator]

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