Swift 3 - Sliding stack views?

620 Views Asked by At

I am currently in process of making a registration form on my app in Swift 3 / xcode and I first have 3 text fields showing with a continue button underneath, I want it so the user presses the continue button and the current stackview slides out of view and a new one slides in (similar to a segue with the storyboards

This will show first and then they press continue:

enter image description here

Then this stack view will show:

enter image description here

Could somebody please point me in the right direction of how to do this?

Thank you.

2

There are 2 best solutions below

0
On BEST ANSWER

For your case, I'm not pretty sure of what is the purpose of using a stackView. I suggest to use UICollectionView (horizontal) instead (UIStackView does not scroll which is inappropriate for what are you trying to achieve), especially that the two views should be the same cell in your case. All you have to do is to check what's the current indexPath.row for determining what cell's components should look/behave.

Also, You can add target to the button to let the collectionView scrolls to the next cell if it's the first row, for the second row it should -for example- submit the form.

Hope it helped.

0
On

@Chad, if you want to use scrollable and easy solution you could try ScrollableStackView library. Here is the github page :

https://github.com/gurhub/ScrollableStackView

Here is some sample codes :

Swift

import ScrollableStackView

var scrollable = ScrollableStackView(frame: view.frame)
view.addSubview(scrollable)

// add your views with 
let rectangle = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 55))
rectangle.backgroundColor = UIColor.blue
scrollable.stackView.addArrangedSubview(rectangle)
// ...

Objective-C

@import ScrollableStackView

ScrollableStackView *scrollable = [[ScrollableStackView alloc] initWithFrame:self.view.frame];
scrollable.stackView.distribution = UIStackViewDistributionFillProportionally;
scrollable.stackView.alignment = UIStackViewAlignmentCenter;
scrollable.stackView.axis = UILayoutConstraintAxisVertical;
[self.view addSubview:scrollable];

UIView *rectangle = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 55)];
[rectangle setBackgroundColor:[UIColor blueColor]];

// add your views with
[scrollable.stackView addArrangedSubview:rectangle]; 
// ...

Hope it helps.