在UIScrollView中更改Alpha [英] Changing the alpha inside UIScrollView

查看:95
本文介绍了在UIScrollView中更改Alpha的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图实现使文本淡入淡出的效果,以显示这篇文章的UIScrollView中有更多数据: UIScrollView,通过滚动文本显示更多数据

I was trying to achieve the effect of having my text fade in and out to show there is more data in the UIScrollView in this post: UIScrollView, showing that there is more data by fading out text

我的背景不是简单的黑白背景,我无法使CAGradientLayer看起来正确,并且我无法使其匹配并使其看起来像文本正在褪色。因此,我想尝试在UIScrollView中设置alpha属性,或在UIScrollView中设置UILabel的alpha属性。但是,它会更改所有文本的字母。有没有办法只对一部分文本或一部分滚动视图做到这一点?谢谢!

I could not get the CAGradientLayer to look right since my background isn't a simple black and white background and I couldn't get it to match and make it look like the text is fading. So I thought I'd try setting the alpha property inside the UIScrollView, or the UILabel's alpha inside the UIScrollView. However, it changes all the text's alpha. Is there a way to do it for only a portion of the text, or a portion of the scrollView? Thanks!

推荐答案

有几种方法,其中至少有两种是相当容易的:

There are several ways, at least two of which are reasonably easy:


  1. 创建带有羽化边缘的背景副本。

  2. 在适当的视图上设置 view.layer.maskLayer (一个UIView包含滚动视图应该可以正常工作)(例如适当设置了content / contentsScale / contentsCenter的CALayer)。更麻烦的是,由于CALayer不会自动调整自身大小(因此,包装视图必须在-setFrame:/-setBounds:/-layoutSubviews中执行必要的操作)。您需要 #include< QuartzCore / CALayer.h>

  1. Create a copy of your background with "feathered" edges. Stick this in a view on top of the scroll view.
  2. Set view.layer.maskLayer on an appropriate view (a UIView containing the scroll view should work) to something suitable (e.g. a CALayer with contents/contentsScale/contentsCenter set appropriately). More of a pain, since CALayer does not autosize itself (so your wrapper view will have to do the necessary things in -setFrame:/-setBounds:/-layoutSubviews). You'll need to #include <QuartzCore/CALayer.h>.

这篇关于在UIScrollView中更改Alpha的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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