How to make a popup window with an image SWIFT

前端 未结 1 1511
轮回少年
轮回少年 2021-02-10 21:02

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

\"\"

The origin window is full of butto

1条回答
  •  有刺的猬
    2021-02-10 21:27

    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. 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.

    Check out UIView animation methods here.

    0 讨论(0)
提交回复
热议问题