Code Monkey home page Code Monkey logo

ios13-self-sizing-cells-issue's Introduction

Update August 19, 2019 - Solution/Workaround

Since logging this issue I found a solution/workaround by using the systemLayoutSizeFitting(_:withHorizontalFittingPriority:verticalFittingPriority:) method. It still looks that there is an issue in iOS 13 with systemLayoutSizeFitting of a UICollectionViewCell because this method is no longer being called as it is on iOS 13 and lower. Now you have to override the systemLayoutSizeFitting(_:withHorizontalFittingPriority:verticalFittingPriority:) method of an UICollectionViewCell and use it as you used to use the systemLayoutSizeFitting.

Code example:

import UIKit

class FlickPhotoCell: UICollectionViewCell {

    func getCellSize(_ targetSize: CGSize) -> CGSize {
        return CGSize(width: 50, height: 200)
    }
    
    // Only this is called on iOS 12 and lower
    override func systemLayoutSizeFitting(_ targetSize: CGSize) -> CGSize {
        return self.getCellSize(targetSize)
    }
    
    // Only this is called on iOS 13 beta
    override func systemLayoutSizeFitting(_ targetSize: CGSize, withHorizontalFittingPriority horizontalFittingPriority: UILayoutPriority, verticalFittingPriority: UILayoutPriority) -> CGSize {
        return self.getCellSize(targetSize)
    }
}

systemLayoutSizeFitting issue in iOS 13 beta

This project illustrates an difference in the way the systemLayoutSizeFitting of a UICollectionViewCell is being called when running the same code on iOS 12.1 and iOS 13.0 beta (Xcode version Version 11.0 beta 2 (11M337n)). This leads to the inability to implement a "self-sizing: cells inside a UICollectionView when running on iOS 13. Also made a thread in Stackoverflow regarding this issue.

The systemLayoutSizeFitting is used to implement the so called "self-sizing" cells inside UICollectionView:

iOS 12.1 (the size of the cell is taken from systemLayoutSizeFittingSize:)

iOS 13 beta (the size of the cell is taken from collectionView:layout:sizeForItemAtIndexPath:)

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.