Changing layout on rotation with multiple views moving - ios

I'm working on an app where I've got a design with two similar layouts for horizontal/vertical. And it's on an iPad. I've found other answers but I can't use most of them because I've got two tableviews in my view, which means I can't use xibs. I'm also making it for the iPad so changing layout based on height/width variation doesn't work.
The design I'm trying to achieve is in the pictures below. What I'm having troubles with is moving the two views that are stacked on the right in landscape mode to be next to each other and short in vertial. Also I need to move those four buttons and the right-side table to being below the other two views.
I've tried overriding trait functions as described in this blog post but for the life of me can not get it to work.
I'm looking for any advice anyone could give me. I feel like I've hit a wall and can not figure out how I can implement this.

just give the height and width constraints of the subviews with respect to the superview in ratio it'll work.

Related

swift 4 and Xcode autoLayout and UIImageview as Button

I am working on auto layout and making those UIIMages as Button.
I would like to make those button to be clicked and switch the images
as well as showing some words in the label.
In this case what should I do?
In addition, as it is shown, the auto layout ratio is different only from the iPhone SE. In. this case What should I consider?
Many thanks,
The first thing you need to learn is auto layout. Start with basic Always go with Apple's doc first
This one I likes he is good and you will also find how to use buttons as image view, using card game example, check other tutorials also very helpfull.
Stanford university autolayout by Michel Deiman
As far, your question just gives your label Horizontal in the container constraints(open storyboard in the right bottom third from last (allin) click on it popUp will open), and 20 bottom to the buttons and it will be in the centre. Every elements need x,y height and width so it knows exactly where to place, so you also need to give constraints to the buttons, Learn stackView to understand how to place your button without giving many constraints to each button and stack view will handle it for you, try hide and show to one of the button and magically stack view will adjust all adjustment. I suggest before staring Do read apple's doc first.
And Your question is too broad to answer, so read and try adding different constraints based on your need and ask a specific question(after trying by yourself) like why this label getting cut what constraints should i add so people know exactly what you want to achieve, people are always ready to help, just ask the right question.
happyCoding

Buttons and Labels Not in Place

I am asking perhaps one of the easiest questions lol but just could not figure it out.
I have some view controllers created based on the screen size of iPhone 7, but when I change devices to iPhone 7plus and iPhoneSE, my labels and buttons were all misplaced...
I have uploaded what they look like in different devices, can somebody please help?
WhatItLooksLikeOniPhone7
WhatItLooksLikeOniPhoneSE
To keep the UI elements at a defined place you need to something that will keep the elements at their position. And hence you need to use autolayout.
Autolayout is basically a constraint based system which will layout the ui elements.
There are many tutorials available.

What's the best way to implement a vertical timeline - iOS

First of all, apologies if this question isn't meant here. I searched a lot but didn't find anything.
What is the best approach to create a vertical timeline kind of view?
I tried implementing via UITableView by alternating cells but that approach is very messy in terms of autolayouting (had to disbale autolayout and apply programtically when creating cell on alternate side), thereofre isn't working properly (getting stuck while scrolling). This is what I achieved:
I want to achieve something like this, which is also easily manageble:
Please Suggest. Thanks!
I would have 1 cell row with two image views. One on the left, one on the right. I think this would be easier to use auto layout.
Then you can hide the image view and labels that shouldn't be used.

How to use auto-layout on a grid?

Maybe I'm going about this the wrong way, but I have a grid like that below and have been futzing around with Auto-layout with only limited success. Currently the cells are individual UILabels that are embedded in UIViews. These views are inside a UIViewController. I've used auto-layout to center the views but this does not solve the problem laying out the labels. I've looked a bit at Container views, but it seems that every cell has to be the same size. Tables? It seems to me that I'd have the same problem in custom table view cell classes. I'm exploring this anyway.
The views look like this:
Can someone tell me a good way to solve this.

Problems with autolayout and resizable views

I have issue with autolayout.
I have three different views (could be n views as well). When I pin first one to top of super view and connect one next to the other everything seems fine. But if I want to change height of first one the other two does not follow (they stay on the same position). What I find weird about this is that if I connect only two views this works perfectly.
To have better understanding what I am trying to achieve I made simple, example solution with three views:
http://i.stack.imgur.com/cMwiB.png
So, when I set height of green view to 0 ( can be any other number as well ) and only red view is connected, this works fine, red will move as it should. Blue one is not connected and it remains where it is:
Here is screenshot when I connect blue to red:
What I tried to do:
connect blue one to green as well ( not working)
connect blue only to green ( not working )
"boxing": have boxes with views at the time ( ugly, hard to manage, not working in all cases)
What I would like to know:
what makes this happen? Can I change this kind of behavior?
What is the best practice to have flexible length for height (Besides UITableView)
Thanks in advance.
Ok, I think you're falling into the same trap I did, when I investigated autolayout some time ago. It's tricky to explain, but I'll do my best. When you work with autolayouts, you need to forget completely about setting a view's frame at all. And that, my friend, includes changing size and positioning. When you use autolayout, you define some constraints, some "rules", that the view tries to respect when rendering the screen, so the more specific the rules are, the less random will be the behavior of the view. I mean, if you just define the spacing between views, you're implying that the height of the views doesn't matter, so it's possible that some views grow or shrink when the re-layout is called (that is, if you don't specify a constraint for size. You probably want to always specify the size of some views in every layout...)
By the way, you're allowed to violate the constraints by manually changing the frame of an element AFTER a re-layout is called, but when the re-layout method is called again, the constraints will be forced so the size and positioning of the views will change. Quick tip: an easy way to force the re-layout method is to change orientation (command+left / command+right in the simulator).
So after saying that, I have to say that the layout you provided is completely working as intended, at least to me. When you change orientations the constraints you specified are ALWAYS being respected. If you want, you can try to apply some frame-setting in the viewDidAppear method, because this one is called AFTER the autolayout (and thus, you're able to violate the constraints temporally). After doing this, your view will be broken but once you change orientation the constraints should be respected again. Make sure it's that way.
From here I can only wish you luck ;) Oh, and refer to the documentation, it was a life saver to me when I looked at this half a year ago. https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/Introduction/Introduction.html It might seem a classic, but it's a pretty nice doc.
EDIT: one last thing. I have the impression that constraints are not designed to be dynamic. You define them once, and they're there always. Their main purpose is to ensure that subviews are rendered as intended in every screen resolution without fail, so if I were to make an application with moving views, I would leave them outside of the autolayout, or avoid using it at all. Just a personal impression though :)

Resources