Weird uitableview behaviour in iOS11. Cells scroll up with navigation push animation

前端 未结 12 1457
粉色の甜心
粉色の甜心 2021-01-29 18:34

I have recently migrated some code to new iOS 11 beta 5 SDK.

I now get a very confusing behaviour from UITableView. The tableview itself is not that fancy. I have custo

12条回答
  •  终归单人心
    2021-01-29 19:12

    Removing extra space at top of collectionView or tableView

        if #available(iOS 11.0, *) {
            collectionView.contentInsetAdjustmentBehavior  = .never
            //tableView.contentInsetAdjustmentBehavior  = .never
        } else {
            automaticallyAdjustsScrollViewInsets = false
        }
    

    Above code collectionView or tableView goes under navigation bar.
    Below code prevent the collection view to go under the navigation

        self.edgesForExtendedLayout = UIRectEdge.bottom
    

    but I love to use below logic and code for the UICollectionView

    Edge inset values are applied to a rectangle to shrink or expand the area represented by that rectangle. Typically, edge insets are used during view layout to modify the view’s frame. Positive values cause the frame to be inset (or shrunk) by the specified amount. Negative values cause the frame to be outset (or expanded) by the specified amount.

    collectionView.contentInset = UIEdgeInsets(top: -30, left: 0, bottom: 0, right: 0)
    //tableView.contentInset = UIEdgeInsets(top: -30, left: 0, bottom: 0, right: 0)
    

    The best way for UICollectionView

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
            return UIEdgeInsets(top: -30, left: 0, bottom: 0, right: 0)
    }
    

提交回复
热议问题