xcode 如何使用图像 SWIFT 制作弹出窗口

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

How to make a popup window with an image SWIFT

iosxcodeswiftpopup

提问by Suit Boy Apps

I was wondering how to make a popup window similar to this example:

我想知道如何制作类似于此示例的弹出窗口:

The origin window is full of buttons that when is selected will then pull up the image I desire to use.

The origin window is full of buttons that when is selected will then pull up the image I desire to use.

回答by tfrank377

I would simply create a reusable UIViewcomponent and everything you need as a subview, such as a UIImageViewfor your image, a UILabelor a UIButtonin the top right. Here is the process to show it:

我会简单地创建一个可重用的UIView组件和您需要的所有内容作为子视图,例如UIImageView您的图像的UILabela UIButton,右上角的a或 a 。这是显示它的过程:

  1. Create a UIViewthat takes up the full screen, make it black, and maybe 0.5 alpha.
  2. Create another UIViewwhich is your primary pop-up view, make it slightly smaller than the previous view, but make sure both of these views are subviews of the parent subview.
  3. Add the desired elements on to the pop-up view as subviews, I would even suggest creating a UIViewsubclass if you plan to use this a lot.
  4. To present the pop-up, make sure both views are set to hidden = truewhen created and so that when a button is selected, you can set them to hidden = false
  5. If you would like them to be animated, simply start them off with alpha = 0.0and use something like UIView's animateWithDurationand set the pop-up view to alpha = 1.0
  1. 创建一个UIView占据全屏,使其变黑,可能还有 0.5 alpha。
  2. 创建另一个UIView作为主要弹出视图的视图,使其比前一个视图略小,但要确保这两个视图都是父子视图的子视图。
  3. 将所需元素作为子视图添加到弹出视图中,UIView如果您打算大量使用它,我什至建议创建一个子类。
  4. 要显示弹出窗口,请确保hidden = true在创建时将两个视图都设置为,以便在选择按钮时将它们设置为hidden = false
  5. 如果您希望它们具有动画效果,只需启动它们alpha = 0.0并使用类似 UIView 的东西animateWithDuration并将弹出视图设置为alpha = 1.0

There is a lot of little details you can change to cater to your needs, but this is the basic structure on how to accomplish your goal.

您可以更改许多小细节以满足您的需求,但这是实现目标的基本结构。

Check out UIView animation methods here.

在此处查看 UIView 动画方法。