Swift - 找出哪个表格视图单元格占据了大部分屏幕 [英] Swift - find out which table view cell occupies most of screen

查看:26
本文介绍了Swift - 找出哪个表格视图单元格占据了大部分屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个表格视图,它的表格视图单元格具有屏幕的宽度和高度.每个显示一个图像.当您滚动表格视图时,您可以让一个表格视图单元格占据整个屏幕.或者您最多可以同时在应用程序的屏幕上看到 2 个表格视图单元格.我的问题是:有什么办法可以找出 2 个表格视图单元格中的哪一个比另一个占据更多的屏幕高度?

I have this table view whose table view cells have the width and the height of the screen. Each showing an image. While you scroll through the table view you can have one table view cell occupying the whole screen. Or at the most you can see 2 table view cells on the screen of the app at the same time. My question is: is there any way I can find out which of the 2 table view cells occupies more screen height than the other?

推荐答案

查看第二个可见单元格 (tableView.visibleCells[1]) 并检查其 y 位置.如果它小于 tableView 高度的一半,它会占用更多的屏幕,否则更少.以任何你想要的方式打破关系.

Look at the second visible cell (tableView.visibleCells[1]) and check its y position. If it's less than half the height of the tableView, it's taking up more of the screen, else less. Break ties any way you want.

编辑

给定indexPath的y位置是固定的,所以需要考虑tableView的contentOffset.

The y position for a given indexPath is fixed, so you need to take into account the tableView's contentOffset.

CGFloat yOrigin = [tableView.visibleCells[1] frame].origin.y - tableView.contentOffset.y;

这篇关于Swift - 找出哪个表格视图单元格占据了大部分屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆