Coder Social home page Coder Social logo

Comments (3)

amirdew avatar amirdew commented on May 11, 2024

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

from collectionviewpaginglayout.

Nahatakyan avatar Nahatakyan commented on May 11, 2024

Thank you!

from collectionviewpaginglayout.

Nahatakyan avatar Nahatakyan commented on May 11, 2024

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)
    }
}

from collectionviewpaginglayout.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.