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
How to make a popup window with an image SWIFT
提问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 UIView
component and everything you need as a subview, such as a UIImageView
for your image, a UILabel
or a UIButton
in the top right. Here is the process to show it:
我会简单地创建一个可重用的UIView
组件和您需要的所有内容作为子视图,例如UIImageView
您的图像的UILabel
a UIButton
,右上角的a或 a 。这是显示它的过程:
- Create a
UIView
that takes up the full screen, make it black, and maybe 0.5 alpha. - Create another
UIView
which 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. - Add the desired elements on to the pop-up view as subviews, I would even suggest creating a
UIView
subclass if you plan to use this a lot. - To present the pop-up, make sure both views are set to
hidden = true
when created and so that when a button is selected, you can set them tohidden = false
- If you would like them to be animated, simply start them off with
alpha = 0.0
and use something like UIView'sanimateWithDuration
and set the pop-up view toalpha = 1.0
- 创建一个
UIView
占据全屏,使其变黑,可能还有 0.5 alpha。 - 创建另一个
UIView
作为主要弹出视图的视图,使其比前一个视图略小,但要确保这两个视图都是父子视图的子视图。 - 将所需元素作为子视图添加到弹出视图中,
UIView
如果您打算大量使用它,我什至建议创建一个子类。 - 要显示弹出窗口,请确保
hidden = true
在创建时将两个视图都设置为,以便在选择按钮时将它们设置为hidden = false
- 如果您希望它们具有动画效果,只需启动它们
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 动画方法。