Iphone UIView子类中使用的CAShapeLayer不';行不通
我用CAShapeLayer尝试了几个小时在我的UIView周围显示一个虚线边框,但没有显示出来。Iphone UIView子类中使用的CAShapeLayer不';行不通,iphone,ios,core-animation,Iphone,Ios,Core Animation,我用CAShapeLayer尝试了几个小时在我的UIView周围显示一个虚线边框,但没有显示出来。 ScaleOverlay.h #import <UIKit/UIKit.h> #import <QuartzCore/QuartzCore.h> @interface ScaleOverlay : UIView <UIGestureRecognizerDelegate> { CAShapeLayer *shapeLayer_; } @end 我在Su
ScaleOverlay.h
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
@interface ScaleOverlay : UIView <UIGestureRecognizerDelegate> {
CAShapeLayer *shapeLayer_;
}
@end
我在Superview中绘制了一个红色矩形,但没有绘制边框。从一个源代码示例中复制了这一点,希望它能起作用,但事实并非如此 您从未将
shapeLayer
添加为UIView层的子层,因此它从未显示在屏幕上。尝试添加
[self.layer addSublayer:shapeLayer_];
在-initWithFrame:
方法中设置CAShapeLayer之后
更好的是,您可以尝试通过重写以下类方法将UIView的支持层设置为CAShapeLayer:
+ (Class) layerClass
{
return [CAShapeLayer class];
}
然后,您可以直接处理视图的层,并消除额外的CAShapeLayer实例变量。简直不敢相信我忘记了
[self.layer addSublayer:shapeLayer_2;]代码>并搜索到天,因为某些原因,您不能使用CAShapeLayer作为背景层。@LucasTizma这里也是。
+ (Class) layerClass
{
return [CAShapeLayer class];
}