【问题标题】:How can I create a custom popup window for iPhone?如何为 iPhone 创建自定义弹出窗口?
【发布时间】:2013-07-17 11:26:09
【问题描述】:

我想为 iPhone 创建一个自定义弹出窗口,它应该如下所示:

在 iPhone 和 iPod 设备上实现此功能的最正确方法是什么?

【问题讨论】:

  • 我认为 iOS 的理念是使用操作表而不是那样的弹出窗口(对于 iPhone 而不是 iPad)。据我所知,没有像 iPhone 这样的内置弹出窗口。
  • @Fonix 以防 iPhone 你的权利,但对于 iPad,我们有 UIPopoverView 来实现这一点。
  • 是的,我确实在我的评论中明确提到了这一点:P

标签: iphone ios objective-c cocoa-touch popup


【解决方案1】:

最好的方法是使用 UIActionSheet。代码在这里:

UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:@"Share" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Facebook",@"Twitter", nil];
[actionSheet showInView:self.view];

UIActionSheet 从底部到顶部带有您希望显示的特定数量的按钮。您还可以放置一个取消按钮,该按钮将自动关闭 UIActionSheet。

下面是它的样子:

【讨论】:

  • 谢谢!!但是您忘记将 添加到类头中,因此您不会收到警告:'Sending ##viewController *const__strong' to parameter of in compatible type 'id'
  • UIActionSheet 现在已弃用。现在使用UIAlertController。见stackoverflow.com/a/32295641/3681880
【解决方案2】:

您应该尝试自定义弹出窗口的第三方类。部分如下

1.) CMPopTipView
2.) KBPopupBubble
3.) ADPopupView

【讨论】:

    【解决方案3】:

    使用第三方控件来执行此操作。

    Here 是您可以下载此项目的链接。

    【讨论】:

      【解决方案4】:

      有很多方法可用。我会亲自执行此代码:

      // create view popup
      UIView *viewPopup = [[UIView alloc] initWithFrame:CGRectMake(x, y, width, height)];
      [self.view addSubview:viewPopup];
      
      // create Image View with image back (your blue cloud)
      UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, width, height)];
      UIImage *image =  [UIImage imageNamed:[NSString stringWithFormat:@"myImage.png"]];
      [imageView setImage:image];
      [viewPopup addSubview:imageView];
      
      // create button into viewPopup
      UIButton *buttonTakePhoto = [[UIButton alloc] initWithFrame:CGRectMake(x, y, width, height)];
      [viewPopup addSubview: buttonTakePhoto];
      [buttonTakePhoto setTitle:@"Take Photo" forState:UIControlStateNormal];
      [buttonTakePhoto addTarget:self action:@selector(actionTakePhoto) forControlEvents:UIControlEventTouchDown];
      [viewPopup addSubview:buttonTakePhoto];
      

      您可以在单击图标相机时为 Alpha viewPopup 设置动画,例如启用/禁用 viewPopup。

      【讨论】:

        【解决方案5】:

        实现您所要求的最简单的方法是创建一个看起来您想要的视图并包含适当的 UIButtons,然后在按下相机按钮时将其添加为子视图(并以您想要的方式为其外观设置动画) .尽管 Fonix 对您的问题的评论是正确的,因为操作表旨在用于 iOS 上的此目的。

        【讨论】:

          猜你喜欢
          • 2021-12-15
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-05-10
          • 1970-01-01
          • 2017-11-16
          • 1970-01-01
          相关资源
          最近更新 更多