简体   繁体   English

如何为iPhone创建自定义弹出窗口?

[英]How can I create a custom popup window for iPhone?

I want to create a custom popup window for iPhone which should look like this: 我想为iPhone创建一个自定义弹出窗口,如下所示: 在此输入图像描述

What is the most correct way to implement this for iPhone and iPod devices? 为iPhone和iPod设备实现此功能的最正确方法是什么?

The best way to do this is using a UIActionSheet. 最好的方法是使用UIActionSheet。 The code is here: 代码在这里:

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

A UIActionSheet comes from the bottom to the top with a certain number of buttons you wish to display. UIActionSheet从底部到顶部,带有一定数量的按钮。 You can also put a cancel button that will automatically dismiss the UIActionSheet. 您还可以放置一个取消按钮,该按钮将自动关闭UIActionSheet。

Here is how it will look like: 以下是它的样子:

在此输入图像描述

You should try third party classes for custom popup windows. 您应该尝试自定义弹出窗口的第三方类。 Some of are as follow 一些如下

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

Used third party control, to do this. 使用第三方控件,执行此操作。

Here is the Link you may download this project. 是您可以下载此项目的链接。

There are many way available. 有很多方法可供选择。 I would do this code personally: 我会亲自做这个代码:

// 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];

You can animated the Alpha viewPopup when click on the Icon Camera such as enable/disable the viewPopup. 单击图标相机(例如启用/禁用viewPopup)时,可以为Alpha viewPopup设置动画。

The easiest way to implement what you are asking would be to create a view that looks how you want and contains the appropriate UIButtons and then add it as a subview (and animating it's appearance how you want) when the camera button is pressed. 实现所要求的最简单方法是创建一个看起来如何的视图,并包含相应的UIButtons,然后在按下相机按钮时将其添加为子视图(并按照您想要的方式设置它的外观)。 Although the comment on your question from Fonix is correct in that action sheets are designed to be used for this purpose on iOS. 虽然Fonix对您的问题的评论是正确的,因为操作表旨在用于iOS上的此目的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM