OGeek|极客世界-中国程序员成长平台

标题: ios - 分页 UIScrollView 上的缩放效果? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 10:57
标题: ios - 分页 UIScrollView 上的缩放效果?

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

https://www.pinterest.com/pin/147141112804210631/

谁能给我一些关于如何做到这一点的指示?在过去的 3 天里,我一直在用头撞墙。



Best Answer-推荐答案


我建议使用分页 UIScrollView 的 scrollView.contentOffset.y 来跟踪滚动,并使用该值来为 UIScrollView 内的 View 转换设置动画。

所以添加您的分页 ScrollView 并将自己设置为委托(delegate)

    paginatedScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, [[self view] bounds].size.width, [[self view] bounds].size.height-paginatedScrollViewYOffset)];
    [self.view addSubview:paginatedScrollView];

    paginatedScrollView.pagingEnabled = YES;
    [paginatedScrollView setShowsVerticalScrollIndicator:NO];
    [paginatedScrollView setShowsHorizontalScrollIndicator:NO];
    [paginatedScrollView setAlwaysBounceHorizontal:NO];
    [paginatedScrollView setAlwaysBounceVertical:YES];
    paginatedScrollView.backgroundColor = [UIColor clearColor];

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

    paginatedScrollView.delegate = self;

然后使用委托(delegate)方法scrollViewDidScroll来跟踪scrollView.contentOffset.y

- (void) scrollViewDidScrollUIScrollView *)scrollView {

    NSLog(@"Scroll Content Offset Y: %f",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

  }

关于ios - 分页 UIScrollView 上的缩放效果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36554774/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4