正确屏蔽 CALayers
我正在使用 TapkuLibrary 的其他优秀 TKCalendarDayEventView 并尝试有选择地将视图中的一个角圆化为 StuDev 在此演示。不幸的是,应用 StuDev 的代码片段会导致 EventView 从其包含的 TKCalendarDayTimelineView 中完全消失。我将此代码片段添加到
+ (id)eventViewWithFrame:(CGRect)frame id:(NSNumber *)id startDate:(NSDate *)startDate endDate:(NSDate *)endDate title:(NSString *)标题位置:(NSString *)位置; 方法
。我已经注释掉了代码中设置边框宽度、颜色或半径的代码。我已确保 TKCalendarDayEventView 没有任何超级层,因为 苹果文档警告不要向具有超级图层的图层添加蒙版:
为新图层设置遮罩时,必须首先将新图层的超级图层设置为 nil,否则行为未定义。
我还尝试过使用 maskLayer 的 backgroundColor 和 fillColor 属性。我在 TKCalendarDayEventView 中没有看到任何可能阻止正确应用此掩码的内容。我可能做错了什么?
I am using the TapkuLibrary's otherwise excellent TKCalendarDayEventView and trying to selectively round one of the corners in the view as StuDev demonstrates here. Unfortunately, applying StuDev's code snippet results in the EventView disappearing entirely from its containing TKCalendarDayTimelineView. I am adding this code snippet underneath the current code in the
+ (id)eventViewWithFrame:(CGRect)frame id:(NSNumber *)id startDate:(NSDate *)startDate endDate:(NSDate *)endDate title:(NSString *)title location:(NSString *)location;
method. I have commented out code that otherwise sets the border width, color, or radius in the code. I have made sure that TKCalendarDayEventView doesn't have any superlayers, since the
apple docs warn against adding masks to layers with superlayers:
When setting the mask to a new layer, the new layer’s superlayer must first be set to nil, otherwise the behavior is undefined.
I have also tried playing around with the backgroundColor and fillColor properties of the maskLayer. I don't see anything in the TKCalendarDayEventView that might stop this mask from being correctly applied. What could I be doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

如果您在
eventViewWithFrame:id:startDate:endDate:title:location:
方法中放置断点,您将看到在创建事件视图时将框架设置为CGRectZero
代码>.然后设置圆角蒙版的代码片段使用 CGRectZero 作为蒙版层的框架。处理这个问题的最简单方法可能是重写
TKCalendarDayEventView
的setFrame:
方法,如下所示:这样,每次更改视图的框架时,蒙版都会自动调整。
If you put a breakpoint in your
eventViewWithFrame:id:startDate:endDate:title:location:
method, you will see that when you create your event view you are setting the frame toCGRectZero
. The code snippet that then sets the rounded corner mask is usingCGRectZero
as the mask layer's frame.Probably the simplest way to deal with this would be to override
TKCalendarDayEventView
'ssetFrame:
method like so:This way, every time you change the frame of the view the mask automatically adjusts.