菜鸟教程小白 发表于 2022-12-12 10:57:22

ios - 分页 UIScrollView 上的缩放效果?


                                            <p><p>我想在我创建的分页 UIScrollView 上实现“缩放”效果,但我遇到了很多困难。我的目标是,当用户开始滚动到下一页时,当前页面会缩小以变得更小。当下一页进入 View 时,它会放大直到变成完整尺寸。我能找到的最接近示例的是这个......</p>

<p> <a href="https://www.pinterest.com/pin/147141112804210631/" rel="noreferrer noopener nofollow">https://www.pinterest.com/pin/147141112804210631/</a> </p>

<p>谁能给我一些关于如何做到这一点的指示?在过去的 3 天里,我一直在用头撞墙。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我建议使用分页 UIScrollView 的 <strong>scrollView.contentOffset.y</strong> 来跟踪滚动,并使用该值来为 UIScrollView 内的 View 转换设置动画。 </p>

<p>所以添加您的分页 ScrollView 并将自己设置为<strong>委托(delegate)</strong>。 </p>

<pre><code>    paginatedScrollView = [ initWithFrame:CGRectMake(0, 0, [ bounds].size.width, [ bounds].size.height-paginatedScrollViewYOffset)];
    ;

    paginatedScrollView.pagingEnabled = YES;
    ;
    ;
    ;
    ;
    paginatedScrollView.backgroundColor = ;

    paginatedScrollView.contentSize = CGSizeMake([ bounds].size.width, [ bounds].size.height*2); //this must be the appropriate size depending of the number of pages you want to scroll

    paginatedScrollView.delegate = self;
</code></pre>

<p>然后使用委托(delegate)方法scrollViewDidScroll来跟踪<strong>scrollView.contentOffset.y</strong> </p>

<pre><code>- (void) scrollViewDidScroll:(UIScrollView *)scrollView {

    NSLog(@&#34;Scroll Content Offset Y: %f&#34;,scrollView.contentOffset.y);
    //use here scrollView.contentOffset.y as multiplier with view.transform = CGAffineTransformMakeScale(0,0) or with view.frame to animate the zoom effect

}
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 分页 UIScrollView 上的缩放效果?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/36554774/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/36554774/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 分页 UIScrollView 上的缩放效果?