Skip to content
This repository has been archived by the owner on Jun 17, 2023. It is now read-only.

How to change aligment from center to left? #42

Closed
Nahatakyan opened this issue Apr 28, 2021 · 3 comments
Closed

How to change aligment from center to left? #42

Nahatakyan opened this issue Apr 28, 2021 · 3 comments
Assignees

Comments

@Nahatakyan
Copy link

In all examples, paging is centered. Is there a way to change paging alignment to left and bottom? Like in the image.

Screen Shot 2021-04-29 at 01 24 09

@amirdew
Copy link
Owner

amirdew commented Apr 29, 2021

Yes you can achieve this in few ways, the simplest one is just adjusting padding around your target view in the cell content view.
something like this:

func setup() {
        // You can use Autolayout too
        let cardFrame = CGRect(x: 0, y: 300, width: 100, height: 160)
        card = UIView(frame: cardFrame)
        card.backgroundColor = .gray
        contentView.addSubview(card)
    }

You also need to touch anchorPoint since you want to keep items on the same base line so

class MyCell: UICollectionViewCell, ScaleTransformView {

    var scaleOptions: ScaleTransformViewOptions {
        .init(
            minScale: 0.6,
            scaleRatio: 0.4,
            translationRatio: CGPoint(x: 0.66, y: 0)
        )
    }

    func transform(progress: CGFloat) {
        card.layer.anchorPoint = .init(x: 0.5, y: 1.5)
        applyScaleTransform(progress: progress)
    }
}

result:
Simulator Screen Shot - iPod touch (7th generation) - 2021-04-29 at 12 47 18

@amirdew amirdew self-assigned this Apr 29, 2021
@Nahatakyan
Copy link
Author

Thank you!

@Nahatakyan
Copy link
Author

Nahatakyan commented Apr 29, 2021

Finally I get what I need with this:

extension Cell: ScaleTransformView {
    var scaleOptions: ScaleTransformViewOptions {
        let minHeight: CGFloat = 220
        let minScale = minHeight / Self.cardSize.height
        let spacing: CGFloat = 16
        let translationRatioXDelta = spacing / cardView.frame.width
        return ScaleTransformViewOptions(
            minScale: minScale,
            scaleRatio: 1 - minScale,
            translationRatio: CGPoint(x: minScale + translationRatioXDelta, y: 0)
        )
    }

    func transform(progress: CGFloat) {
        let leftInset: CGFloat = 20
        let x = 0.5 - (leftInset / cardView.frame.width)
        let height = Self.cardSize.height - cardView.frame.height
        let y = 0.5 - (height / cardView.frame.height)
        cardView.layer.anchorPoint = CGPoint(x: x, y: y)
        applyScaleTransform(progress: progress)
    }
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants