BroSimple BroSimple - 3 years ago 270
iOS Question

Swift: Full screen UIImageView not working

Using Swift, I want to click a smaller image view which then expands to full screen of the device and once clicked again to go back to the default size it was before.

This is the code I have but when clicked it doesn't expand to full screen more as in, it expands to the views width.

I have a pop up UIView on top of my main view to show as a pop up and the image expands to that pop up view but not the whole screen.

Before clicking imageView

After clicking imageVjew

How would I achieve a full screen of my imageView?

@IBOutlet var backgroundView: UIView!
@IBOutlet weak var popUpView: UIView!
@IBOutlet weak var iconImage: UIImageView!

override func viewDidLoad() {

let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTap(_:)))


@IBAction func handleTap(_ gesutureRecognizer: UITapGestureRecognizer) {

let screenSize = UIScreen.main.bounds
let screenWidth = screenSize.width
let screenHeight = screenSize.height
iconImage.frame = CGRect(x: 0, y: 0, width: screenWidth, height: screenHeight)

Answer Source

You can follow the logic of this tutorial, but instead of creating a UIViewController for the "popup" you can create an UIViewController with an imageView in fullscreen mode.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download