如何从代码中以编程方式设置 uiimageview 的大小以在我的 swift 应用程序中覆盖全屏? [英] How can I set programmatically from code the size of uiimageview to cover full screen in my swift app?

查看:32
本文介绍了如何从代码中以编程方式设置 uiimageview 的大小以在我的 swift 应用程序中覆盖全屏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这实际上是对这个问题的跟进 - 当用户在 Swift 中点击我的 UIImage 时,如何全屏显示图像?

This is actually a follow up to this question - How can I display image on fullscreen when user taps on my UIImage in Swift?

我设法向我的 uiimageview 添加了一个点击侦听器,但现在我想在用户单击它时展开它.我有一张照片的 iboutlet:

I managed to add a tap listener to my uiimageview, but now I would like to expand it when user clicks it. I have an iboutlet for that photo:

@IBOutlet weak var requestPhoto: UIImageView!

然后监听器打印这个字符串:

and then the listener so far prints this string:

func tapHandler(sender: UITapGestureRecognizer) {
    if sender.state == .Ended {
        print("photo tapped")
    }
}

现在我不想打印字符串,而是想在全屏上显示照片,但这样它就可以在任何尺寸的 iphone 屏幕上工作 - 有没有办法直接从代码中做到这一点?

Now instead of printing the string I want to show the photo on the full screen, but so that it could work on any size of the iphone screens - is there a way of doing that directly from the code?

推荐答案

很容易 :

self.requestPhoto.frame = self.view.frame

但请记住,旋转屏幕后不会进行调整.如果您同时支持纵向和横向,最好摆脱约束并操纵它们.

Bear in mind though, that this will not adjust after rotating the screen. If you support both portrait and landscape it would be best to get outlest for constraints and manipulate them.

此外,此方法将保留导航栏和标签栏(照片不会覆盖它们).如果你想要全"全屏,你应该采用 UIWindow

Also this method will preserve navigation and tab bars (the photo won't cover them). If you want "full" fullscreen, you should take the frame of UIWindow

这篇关于如何从代码中以编程方式设置 uiimageview 的大小以在我的 swift 应用程序中覆盖全屏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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