[英]How can I set programmatically from code the size of uiimageview to cover full screen in my swift app?
This is actually a follow up to this question - How can I display image on fullscreen when user taps on my UIImage in Swift? 这实际上是此问题的后续措施- 当用户在Swift中点击我的UIImage时,如何全屏显示图像?
I managed to add a tap listener to my uiimageview, but now I would like to expand it when user clicks it. 我设法在我的uiimageview中添加了一个监听器,但是现在我想在用户单击它时对其进行扩展。 I have an iboutlet for that photo: 我有一张照片的iboutlet:
@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")
}
}
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? 现在,我不想打印字符串,而是想在全屏上显示照片,但是它可以在任何尺寸的iphone屏幕上工作-有没有办法直接从代码中做到这一点?
Quite easily : 很容易:
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. 如果同时支持纵向和横向,则最好不拘一格地进行约束并加以处理。
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 如果要“全屏”全屏,则应采用UIWindow的框架
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.