如何使用图像SWIFT创建一个弹出窗口 [英] How to make a popup window with an image SWIFT

查看:605
本文介绍了如何使用图像SWIFT创建一个弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何创建一个类似于这个例子的弹出窗口:

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.

推荐答案

我只想创建一个可重复使用的 UIView 组件以及作为子视图所需的一切,例如作为您的图像的 UIImageView UILabel UIButton 在右上角。以下是显示它的过程:

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:


  1. 创建一个 UIView ,它占用了全屏,让它变成黑色,也许是0.5 alpha。

  2. 创建另一个 UIView 这是你的主要弹出视图,制作它稍微小于上一个视图,但请确保这两个视图都是父子视图的子视图。

  3. 将所需元素作为子视图添加到弹出视图中,我甚至建议如果你计划使用它,可以创建一个 UIView 子类。

  4. 要显示弹出窗口,请确保设置了两个视图在创建时 hidden = true ,以便在选择按钮时,可以将它们设置为 hidden = false

  5. 如果你想要它们的动画,只需用 alpha = 0.0 启动它们并使用类似UIView的 animateWithDuration 并将弹出视图设置为 alpha = 1.0

  1. Create a UIView that takes up the full screen, make it black, and maybe 0.5 alpha.
  2. 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.
  3. 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.
  4. 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 to hidden = false
  5. If you would like them to be animated, simply start them off with alpha = 0.0 and use something like UIView's animateWithDuration and set the pop-up view to 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.

查看UIView动画方法此处

Check out UIView animation methods here.

这篇关于如何使用图像SWIFT创建一个弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆