Ramprasath Selvam
Ramprasath Selvam

Reputation: 4448

ios swift change orientation will change UIView Design

In My project
change orientation will change UIView Design for same ViewController
Portrait:
enter image description here

Landscape
enter image description here

in same ViewController change the design for different orientation styles.

Upvotes: 1

Views: 1077

Answers (2)

Devang Tandel
Devang Tandel

Reputation: 3008

The answer you are looking for is UIStackView

Here is Apple Doc if you really want to go into it

Implementing UIStackView is easy

1) Select the all views you want to take effect 2) Select Embed in Stackview like displayed in image below

Using UIStackview

3) Setup your UIStackView

enter image description here

Here how your UIStackview property will look like.

enter image description here

UIStackView manage your screen rotation and you can have two different layouts as you desire.

Upvotes: 4

Aleksandr Honcharov
Aleksandr Honcharov

Reputation: 2513

You should look at Size Classes concept. For example, watch this video on youtube to understand how it works. https://youtu.be/7iT9fueKCJM

Also you can setup your constraints programmatically after rotation:

override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
        super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)

        if (UIDevice.currentDevice().orientation.isLandscape) {
            // ------ Landscape -----
            // Setup constraints

        } else {
            // ----- Portrait -----
            // Setup constraints
        }
    }

Upvotes: 2

Related Questions