当UIImageView接近UIScrollView的边缘时淡出它 [英] Fade UIImageView as it approaches the edges of a UIScrollView

查看:105
本文介绍了当UIImageView接近UIScrollView的边缘时淡出它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序底部的图像上有一个UIScrollView,它可以作为一个带有可以水平滚动的图标的底座。而不是UIScrollView的粗糙边缘,我希望图标淡出以获得更美观的外观。作为iOS开发的新手,我不知道其中任何一个是否是有效的选项:

I have a UIScrollView over an image at the bottom of my app that acts as a dock with icons that can be scrolled through horizontally. Instead of the harsh edges of the UIScrollView, I would like the icons to fade out for a more aesthetically pleasing look. Being new to iOS development, I don't know if either of these would be valid options:


  1. 创建一个褪色的图像用作覆盖在滚动视图上,因此
    图标仅通过可见部分显示。

  2. 实际上根据图像与中心的距离(或每个边缘
    )更改图像的
    alpha。

我怀疑第一个想法是最简单的,但我想把它扔到那里以获得任何其他想法。

I suspect the first idea would be the most simple, but I'd like to throw this out there for any other ideas.

注意:我确实看到这个教程,但该技术假设背景是纯色。如果我以编程方式进行,我可能需要淡化单个图像。

Note: I did see this tutorial, however that technique assumes that the background is a solid color. If I were to do it programatically, I would probably need to fade the individual images.

推荐答案

你绝对可以在第2行。它与教程描述的内容类似。然而,alpha转换不会像使用教程中提到的渐变层或使用图像那样平滑,因为整个图标将具有相同的alpha。差异多大程度取决于图标的大小。较小的图标,很少能够分辨出来。较大的图标差别很明显。

You can definitely implement something along the lines of #2. It'd be something similar to what the tutorial describes. The alpha transition however won't be as smooth as using the gradient layer mentioned in the tutorial or using an image since the entire icon would have the same alpha. How much discernible the difference is depends on the size of your icons. Smaller icons, very few will be able to tell the difference. Larger icons the difference would be quite clear.

你必须实现


  • (void)scrollViewDidScroll:(UIScrollView *)scrollView

滚动视图的委托类中的方法。每次滚动视图更改其内容的位置时,都会调用此方法。在此方法中,您可以调用其子视图并根据需要调整其alpha。要优化它而不是在所有元素上调用alpha调整,您只需更新仍然部分/完全可见的子视图。

method in your scroll view's delegate class. This method will get called every time the scroll view changes the location of its content. In this method you can call its subviews and adjust their alphas as required. To optimize it a bit instead of calling the alpha adjustments on all the elements you can just update the subviews which are still partially/completely visible.

编辑:找出哪个要调整的视图将使用在上述方法中作为参数传递的scrollView的contentOffset属性。

to figure out which views to adjust you'll use the contentOffset property of the scrollView that gets passed as a parameter in the above method.

这篇关于当UIImageView接近UIScrollView的边缘时淡出它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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