如何屏蔽 UIScrollView? [英] How to mask a UIScrollView?
本文介绍了如何屏蔽 UIScrollView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前有一个图像遮罩,我想用它来遮罩 UIScrollView.滚动视图包含 1 个 UIImageView.
I currently have an image mask I want to use to mask a UIScrollView. The scrollview holds 1 UIImageView.
这是我目前在 viewdidload 中所做的:
Here is what I do at the moment in viewdidload:
CALayer *mask = [CALayer layer];
mask.contents = (id)[UIImage imageNamed:@"ScrollMask.png"].CGImage;
mask.frame = CGRectMake(0, 0, 512, 384);
[Scroll1.layer setMask:mask];
这在某种程度上有效.它掩盖了滚动视图内的 ImageView,但不掩盖滚动视图本身.
This works to some degree. It masks the ImageView inside the scrollview but not the scrollview itself.
有没有办法屏蔽滚动视图的 CALayer 而不是 imageview 的层?
Is there a way to mask the scrollview's CALayer and not imageview's layer?
推荐答案
你应该把 UIScrollView 放到 UIView 中,然后将 mask 应用到 UIView 而不是 UIScrollView.
You should put the UIScrollView into a UIView, and then apply the mask to the UIView instead of the UIScrollView.
CALayer *mask = [CALayer layer];
mask.contents = (id)[UIImage imageNamed:@"ScrollMask.png"].CGImage;
mask.frame = CGRectMake(0, 0, 512, 384);
UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 512, 384)];
[containerView.layer setMask:mask];
[containerView addSubview:Scroll1];
[self.view addSubview:containerView];
这篇关于如何屏蔽 UIScrollView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文