AutoLayout with ScrollView in Swift - ios

I have just joined iOS Develepors world.
i have a questions.
I don't understand auto layout with scrollview. Im tried every kind method but everytime seen different size and different location (button).
I just want to create scrollview (hortizonal) on 12 buttons for all IPhone models. What should i do? Could you write details.
Thank you so much.

It's pretty easy, you just have to be really methodic with all the constraints you add. I always start from the outside constraints and then start adding the inner ones.
Check out the tutorial I wrote for implementing a UIScrollView + Auto Layout in Swift. If you have any doubt, just ask me :)
https://www.dribba.com/blog/2015/07/21/scrollview-autolayout-ios8-swift/

Related

Changing layout on rotation with multiple views moving

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.

How to enable scroll in UICollectionView?

I’m still learning to develop in iOS and Swift so I apologize beforehand if my question is too simple.
I have created an UICollectionViewController to show a matrix of elements. My issue is that the width of the screen is not wide enough to fit all the columns in a single row, so the excess of them are shown in another row below. Instead of this, I’d like to enable the horizontal scroll so the user can scroll to see all the columns in one single row.
I know UICollectionViewController already contains UIScrollView so I guess this should be as simple as to change a setting in the .storyboard but I couldn’t find it after many trial-errors :(
I guess it is related to the "Flow" layouts setting and that I need to handle a custom one, but don't know how exactly.
Would anyone be so kind to please help me? I haven’t attached any code because I’m using a pretty standard/out-of-the-box implementation of UICollectionViewController but if you want me to add anything, just let me know, please.
Many thanks in advance for any help!
I found the answer to my issue perfectly covered on this post:
https://www.credera.com/blog/mobile-applications-and-web/building-a-multi-directional-uicollectionview-in-swift/
It's definitely to do with your UICollectionViewLayout — that tells the collection view where everything should go. The collection view simply picks its scroll behaviour appropriately.
A UICollectionViewFlowLayout is a specific type of layout that fills one row column to the size of the enclosing view, then moves on to the next. So it does one-dimensional scrolling. Does that fit your use case?
If so then you should just be able to set the scroll direction on the flow layout.
If not then you'll need to write a custom subclass of UICollectionViewLayout that implements the layout behaviour you want.

ScrollView using storyboard

I'm new to swift programming and storyboard usage. I want to know if it is possible to place my views inside a ScrollView using Storyboard and AutoLayout but visually. I'm not an expert so programming the constraints is a little hard for me now.
If it's possible can someone point me to a good starting point using xCode 6+. I'm planning to use iOS8+ as a requirement.
Thanks all!
It's pretty easy!
I've written a tutorial that explain how to use UIScrollView with Auto Layout in iOS 8 and Swift.
Take a look, hopefully will help you :).
https://www.dribba.com/blog/2015/07/21/scrollview-autolayout-ios8-swift/
Yes, it is possible. I do it all the time in my current projects.
Just make sure you connect (auto layout constraints) your scrollable contents to all sides of the scrollview, so that it can calculate the content size correctly.
Autolayout + UIScrollView is not a simple topic. Apple has a technical note on it:
https://developer.apple.com/library/ios/technotes/tn2154/_index.html
I found these tutorials useful:
http://natashatherobot.com/ios-autolayout-scrollview/
http://mobileoop.com/auto-layout-advanced-techniques-for-ios-8-and-7-using-xcode-6-on-storyboard
http://spin.atomicobject.com/2014/03/05/uiscrollview-autolayout-ios/?utm_source=maniacdev-ao&utm_medium=social&utm_campaign=uiscrollview-autolayout-ios

Autolayout with UIScrollView containing dynamic TableView height

I have a little problem, I work with Xcode 6 and now as we could see Apple advised to use Autolayout in our apps... And now that's compulsory.
So, I have that problem: I want to layout the ScrollView and the TableView but, I don't know how to do because I'm not an expert of autolayout...
The TableViewCells are dynamics, and appears by a specific action (for example: when a button is tapped) and the ScrollView's resizing automatically and that's the same for TableView's height.
As I said, I want the TableView's height and the ScrollView's height to change automatically and to adapt autolayout with this... But I don't have any idea yet...
Is anyone able to help me ? Please, if you have an idea tell me to hope to solve the problem !
Thank you in advance, and have a nice day ! (sorry I really wanted to post images but I can't currently because of reputation....................)
I always put something with blue lines, so I can use AL's suggest constraints at the third button on the bottom right, or use option + shift +command + '=' key to reset suggested constraints.By the way, Watching Stanford ios7 lecture 9 on itunes U is a good way learning autolayout.

Moving content of UITableViewCell on tap

If anyone have Google+ App can certainly understand what I'm trying to implement.
(explained here: UIViewController Containment with animation like Google+)
I think it has something related with the new effect in iOS 7 Calendar App.(explained here: Recreating iOS 7 Calendar UIView Animation)
-
This is a common animation effect that I'm seeing in many apps these days.
Months ago, the fellow Rob tried to help me with this his answer:
Now I was trying to implement it but there's a problem. Images explains better:
INITIAL STATE
WHAT HAPPEN WITH CURRENT IMPLEMENTATION
WHAT SHOULD HAPPEN
I've created a super simple project that shows the implementation (few lines).
Can someone help me to find where's the problem?
REPO: https://github.com/socksz/MovingTableViewCellContent
The problem is that you're trying to change the view's frame with Auto Layout on. You can't do that. The Auto Layout system will overwrite your changes. Try turning off Auto Layout in your storyboard and you'll see that it works.
So your options are:
Don't use Auto Layout
Use/manipulate constraints instead of frames.
For (2) you can just go into the storyboard and set up width and height constraints on the container view and it will work. If fixed size isn't the exact behavior you want, you'll need to be more explicit in your requirements.
The default constraints you're getting now are attached to the parent view and aren't getting carried along for the ride when you move the view to a new parent.

Resources