How can I set programmatically from code the size of uiimageview to cover full screen in my swift app?

大憨熊 提交于 2020-01-06 18:00:32

问题


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

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")
    }
}

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?


回答1:


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




回答2:


  1. You can set transparent UIButton and connect to another ViewController
  2. Create new Viewcontroller and set new UIImageView
  3. Go to Storyboard click segue symbol line and go to Right Panel Asisten Inspector
  4. Set Kind: Present Modally - Presentation: Current Context : Animates

Storyboard Segue



来源:https://stackoverflow.com/questions/36094792/how-can-i-set-programmatically-from-code-the-size-of-uiimageview-to-cover-full-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!