菜鸟教程小白 发表于 2022-12-12 09:33:27

ios - 获取每个 UITableViewCell 屏幕上的当前 y 值位置


                                            <p><p>我有一个 <code>UITableViewController</code>,其中包含用于我的 <code>UITableViewCell</code> 的自定义类。我在这个 <code>UITableViewCell</code> 上有一个 <code>UIImageView</code> 和一个 <code>UILabel</code>。</p>

<p>我希望 <code>UITableViewCell</code> 上的内容在屏幕上高于某个 y 值时变得更加半透明/透明,这样你就可以得到类似于 Rdio 的“淡入淡出效果”应用:</p>

<p> <img src="/image/2YulH.png" alt="The alpha value of the &lt;code&gt;UIImageView&lt;/code&gt; and UILabel are 1.0"/>
<img src="/image/343bd.png" alt="Now the value is lower, like 0.7 or something."/> </p>

<p>MyUIViewController.h</p>

<pre><code>@property (strong, nonatomic) IBOutlet UITableView *tableview;
</code></pre>

<p>MyUIViewController.m</p>

<pre><code>@synthesize tableview;

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {

    NSArray *listOfVisibleCells = tableview.visibleCells;

    for (int i=0; i&lt;; i++) {

      MTTableViewCell *cell = ;

      /* Smooth fade out */
      if (scrollView.contentOffset.y &gt; (cell.frame.origin.y + 10)) {
            ;
      }
      if (scrollView.contentOffset.y &gt; (cell.frame.origin.y + 20)) {
            ;
      }
      if (scrollView.contentOffset.y &gt; (cell.frame.origin.y + 30)) {
            ;
      }
      if (scrollView.contentOffset.y &gt; (cell.frame.origin.y + 40)) {
            ;
      }

      /* Fade in */
      if (scrollView.contentOffset.y &lt; (cell.frame.origin.y + 10)) {
            ;
      }
    }
}
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>这一行:</p>

<p><code>if (scrollView.contentOffset.y > ((i*90)+30) ) {</code></p>

<p>应该是:</p>

<p><code>if (scrollView.contentOffset.y > (cell.frame.origin.y + 30)) {</code></p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 获取每个 UITableViewCell 屏幕上的当前 y 值位置,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/23325835/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/23325835/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 获取每个 UITableViewCell 屏幕上的当前 y 值位置