简体   繁体   English

如何通过uiimageview大小的代码以编程方式设置以覆盖我的Swift应用程序的全屏显示?

[英]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的框架

  1. You can set transparent UIButton and connect to another ViewController 您可以设置透明的UIButton并连接到另一个ViewController
  2. Create new Viewcontroller and set new UIImageView 创建新的Viewcontroller并设置新的UIImageView
  3. Go to Storyboard click segue symbol line and go to Right Panel Asisten Inspector 转到情节提要板,单击segue符号行,然后转到右面板Asisten检查器
  4. Set Kind: Present Modally - Presentation: Current Context : Animates 设置种类:模态呈现-呈现:当前上下文:动画

Storyboard Segue 情节提要Segue

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Swift:全屏UIImageView无法正常工作 - Swift: Full screen UIImageView not working 如何防止我的Phonegap应用在ios上全屏播放视频? - How can I prevent my Phonegap app from playing video full screen on ios? 如何让我的 flutter 应用程序覆盖整个 android 屏幕(删除应用程序侧面的白条) - How to make my flutter app cover the full android screen (Remove white bars on the side of the app) 如何将UIImageView内容保存到图库? (迅速) - How can I save my UIImageView contents to my gallery? (Swift) 如何在Swift中使用UISlider在UIImageView中以编程方式更改指定的图像大小 - How to change specified image size in UIImageView with UISlider in Swift programmatically 如何以编程方式刷新应用程序屏幕? - How can I refresh the app screen programmatically? iOS应用程序背景完整大小无法覆盖完整 - IOS app background full size not cover full 如何以编程方式更改UIImageView的高度? - How can I change the height of an UIImageView programmatically? 如何在 NativeScript 中以编程方式创建 UIImageView? - How can I create a UIImageView programmatically in NativeScript? 如何使用Swift在屏幕中心水平或垂直设置UIImageView,但不再使用StoryBoard - How to set UIImageView in the center of screen horizontally or vertically with Swift, but no more StoryBoard
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM