user3766930
user3766930

Reputation: 5839

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?

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?

Upvotes: 0

Views: 1802

Answers (2)

Victor Santos
Victor Santos

Reputation: 539

  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

Upvotes: 0

Losiowaty
Losiowaty

Reputation: 8006

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

Upvotes: 1

Related Questions