Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Landscape Option #1

Open
dhruveonmars opened this issue Jun 8, 2017 · 10 comments
Open

Landscape Option #1

dhruveonmars opened this issue Jun 8, 2017 · 10 comments
Labels
enhancement good first issue This issue is good for beginners to start contributing. help wanted

Comments

@dhruveonmars
Copy link

Hey, I love that someone came out with this.

I was wondering if you plan on, or could add an option to use it in Landscape rather than in Portrait only.

@LeonardoCardoso
Copy link
Owner

Hey, @dhruveshah. Thanks.
Not right now.

@dhruveonmars
Copy link
Author

dhruveonmars commented Jun 8, 2017

@LeonardoCardoso Would I simply be able to rotate the view to get it in landscape? or would I have to go into the code and swap the heights and widths that are being set?

@LeonardoCardoso
Copy link
Owner

I don't think this would work because the dragging is calculated by the view's height. But if you change that in the code might work.

@dhruveonmars
Copy link
Author

Hey @LeonardoCardoso
I've managed to get it working horizontally, but it seems to work from right-to-left rather than left-to-right. Any idea what in the modified code that I've attached could be causing this?

SectionedSlider.swift.zip

@LeonardoCardoso
Copy link
Owner

@dhruveshah What lines have you changed?

@dhruveonmars
Copy link
Author

dhruveonmars commented Jun 9, 2017

@LeonardoCardoso I changed quite a lot so it uses the width instead of the height.

First, at the top, I changed on line 21, the ResizingBehavior to .stretch
I swapped the values of width and height around, so the width is 400 instead, and the height is now 156

On line 37, I changed from let sectionHeight: CGFloat = sectionOriginalHeight / sectionsSafe to let sectionWidth: CGFloat = sectionOriginalWidth / sectionsSafe, and everywhere sectionHeight was being called to sectionWidth.

Then, I changed the y1-y20 to x1-x20, and changed the calculation in there from using sectionOriginalHeight to sectionOriginalWidth.

Then in bodyBackgroundViewPath and bodyViewPath I swapped the x and y values. Again, from line 100 to 110, I swapped the x and y values.

In the rectangle20Path to rectangle1Path, I swapped the width from sectionOriginalWidth to sectionWidth, and the height from sectionHeight to sectionOriginalHeight. I also set the x values to 0, and set the y values to y20-y1.

I then changed the scales.height and scales.width values in each switch case in the ResizingBehavior.

Lastly, in the function, touchedX, I swapped it from:

var x = self.frame.height - touch.location(in: self).y
x = x < 0 ? -1 : (x > self.frame.height ? self.frame.height : x)

factor = x / self.frame.height

to

var x = self.frame.width - touch.location(in: self).x
x = x < 0 ? -1 : (x > self.frame.width ? self.frame.width : x)

factor = x / self.frame.width

@LeonardoCardoso
Copy link
Owner

I'll take a look when I have more time. I have to rethink that.

@dhruveonmars
Copy link
Author

@LeonardoCardoso So, I found a "rough working solution". Probably not the best way to get it working, but I changed the following and it seems to work. I'm sure there is a more elegant solution that can be derived from this
In the touchedX function at the bottom, I changed it to:

        var x = self.frame.width - touch.location(in: self).x
        x = x < -1 ? 0 : (x > self.frame.width ? self.frame.width : x)

        print("1testing", x)
        
        if x == self.frame.width {
            x = -1
            print("2testing", x/self.frame.width)
        }
        else {
            x = self.frame.width - x
            print("3testing", x)
        }
        factor = x / self.frame.width

and changed context.rotate(by: -180 * CGFloat.pi/180) to context.rotate(by: 0 * CGFloat.pi/180) in the // SectionedMask Drawing

@LeonardoCardoso LeonardoCardoso added help wanted good first issue This issue is good for beginners to start contributing. labels Apr 7, 2019
@danielVebman
Copy link

@dhruveonmars, @LeonardoCardoso, this is 2 years late, but I put together a version of this sectioned slider myself. Along with some minor improvements, my version allows you to initialize the SectionedSlider with a portrait or landscape orientation.

I might make it its own page at some point, but for now the code is here. All you have to do is copy the file into your project. If it doesn't help you, hopefully it helps someone else passing through this thread.

@maxmika
Copy link

maxmika commented Sep 23, 2019

@danielVebman I think you forgot to call the delegate.

Add this to the end of your handleGesture func:

if gesture.state == .ended {
    delegate?.sectionedSlider(self, selected: value)
}

Also you should always declare protocols as a class type and make the delegate a weak var.

Apart from that your version worked fine for me. Thanks a bunch! 🍻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement good first issue This issue is good for beginners to start contributing. help wanted
Projects
None yet
Development

No branches or pull requests

4 participants