2

uiimageview大家好,当我向下滚动时,我正在尝试使用动画放大uiscrollview。请注意,它不是关于uiimageview放大和缩小uiscrollview.

我能够检测到我向下滚动了多少:

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

我需要缩小图像,具体取决于(滚动因子)我向下滚动的程度。知道如何做到这一点吗?

在此处输入图像描述

4

2 回答 2

12

我建议更改transform您尝试缩放的图像的属性

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

    // this is just a demo method on how to compute the scale factor based on the current contentOffset
    float scale = 1.0f + fabsf(scrollView.contentOffset.y)  / scrollView.frame.size.height; 

    //Cap the scaling between zero and 1
    scale = MAX(0.0f, scale);

    // Set the scale to the imageView
    imageView.transform = CGAffineTransformMakeScale(scale, scale);    
}

如果您还需要滚动视图转到图像视图已缩小的顶部,那么您将需要调整滚动视图和图像视图的框架。

也许你可以告诉我们更多你想要的效果。

于 2013-08-02T11:35:15.753 回答
3

这是安德烈答案的 Swift 版本。如果用户向上滑动(向下滚动),我也会提前退出,因为我只想在他们下拉表格视图时显示缩放效果。

// Exit early if swiping up (scrolling down)
if scrollView.contentOffset.y > 0 { return }

// this is just a demo method on how to compute the scale factor based on the current contentOffset

var scale = 1.0 + fabs(scrollView.contentOffset.y)  / scrollView.frame.size.height

//Cap the scaling between zero and 1
    scale = max(0.0, scale)

// Set the scale to the imageView
self.imageView.transform = CGAffineTransformMakeScale(scale, scale)
于 2016-05-14T21:57:16.787 回答