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.
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() {
super.viewDidLoad()
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTap(_:)))
iconImage.addGestureRecognizer(tapGesture)
}
@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)
}
handleTap(_:)
an@IBAction
if you are creating it in code? Change@IBAction
to@objc
and see if that makes a difference. – Bradley Mackey Oct 2 '17 at 16:05layoutIfNeeded()
oniconImage
after you change its frame – TNguyen Oct 2 '17 at 16:07