小编Fra*_*ank的帖子

更改所选CAShapeLayer的fillColor

我试图在触摸包含它的图层时更改CAShapeLayer的fillColor.我可以像这样更改tapped图层的背景颜色:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
CALayer *layer = [(CALayer *)self.view.layer.presentationLayer hitTest:point];
layer = layer.modelLayer;
layer.backgroundColor = [UIColor blueColor].CGColor;
}
Run Code Online (Sandbox Code Playgroud)

这将"层"的背景变为预期的蓝色.我的问题是如何在"图层"中更改CAShapelayer的颜色?谢谢!

iphone core-animation objective-c calayer

8
推荐指数
1
解决办法
8714
查看次数

使用CGPathRef屏蔽CGContext?

我正在使用CGContext进行绘图.我目前正在使用像这样的png文件来屏蔽绘图:

UIImage * myImage = [UIImage imageNamed:@"frame.png"];
CGContextRef context = UIGraphicsGetCurrentContext ();
CGContextClipToMask(context, self.view.bounds, myImage.CGImage);
Run Code Online (Sandbox Code Playgroud)

这很好,但现在我想使用现有的CGPathRef作为我的掩码.我应该看看如上所述将CGPathRef转换为UIImage和掩码吗?如果是这样,我将如何进行转换? - 或者 - 有更好的方法来解决这个问题吗?

core-graphics objective-c cgpath

8
推荐指数
1
解决办法
4147
查看次数

使用cache.addAll 可以添加的文件数量是否有限制?

我正在开发一个缓存优先的渐进式 Web 应用程序。当我使用 cache.addAll 将文件添加到缓存时,它会在 50 个文件时停止加载。我传递了 150 个 url 的数组,只有 50 个文件传输到缓存(按字母顺序排列)。我尝试过使用少至 60 个文件,但结果相同。所有文件的总文件大小为 1.4Mb,文件均为 .txt 文件。我测试过的所有桌面浏览器(Chrome、Firefox、Safari 和 iOS)都会出现这种情况。当我使应用程序脱机时,它缓存的 50 个文件中的任何一个都可用。我在控制台中没有收到任何错误。我是否达到了某种文件限制,或者有什么方法可以解决这个问题?

service-worker progressive-web-apps

5
推荐指数
0
解决办法
84
查看次数

hitTest重叠CALayers

我有一个UIView,其中包含我使用CALayers作为子图层添加的图形.它是一个红色正方形,内部有一个蓝色三角形.我可以使用以下代码确定触摸了哪个形状:

CGPoint location = [gesture locationInView:self.view];
CALayer* layerThatWasTapped = [self.view.layer hitTest:location];
NSLog(@"Master Tap Location: %@", NSStringFromCGPoint(location));
NSLog(@"Tapped Layer Name: %@", layerThatWasTapped.name);
NSLog(@"Tapped Layer Parent: %@", layerThatWasTapped.superlayer.name);

int counter = layerThatWasTapped.superlayer.sublayers.count;
NSArray * subs =  layerThatWasTapped.superlayer.sublayers;

//Loop through all sublayers of the picture
for (int i=0; i<counter; i++) {
CALayer *layer = [subs objectAtIndex:i];
CAShapeLayer* loopLayer = (CAShapeLayer*)layerThatWasTapped.modelLayer;
CGPathRef loopPath = loopLayer.path;
CGPoint loopLoc = [gesture locationInView:cPage];        
loopLoc = [self.view.layer convertPoint:loopLoc toLayer:layer];
NSLog(@"loopLoc Tap Location: %@", NSStringFromCGPoint(loopLoc));

//determine if hit is …
Run Code Online (Sandbox Code Playgroud)

iphone core-animation objective-c calayer

1
推荐指数
1
解决办法
2749
查看次数

如何将CGPath保存到文件

我在CALayers中绘制了大约20个简单的形状,如下面的那个(在CAShapelayer中绘制的CGPath).现在我有一个非常长的文件,包含这种格式的所有20个形状.当创建父UIView时,它会根据前一个屏幕中选择的内容加载其中一个形状.这样做很好,但保持形状代码太麻烦了.将下面的代码块存储到单个文件中的最佳方法是什么?我可以在需要时调用并执行它(例如:star.txt,apple.txt,moon.txt,tree.txt):

CALayer* root = [[CALayer alloc] init];
root.name = nil;
root.bounds = CGRectMake(0.000000, 0.000000, 768.000000, 768.000000);
root.frame = CGRectMake(0.000000, 0.000000, 768.000000, 768.000000);
[root addSublayer:root];
[root release];
CALayer* root_layer1 = [[CALayer alloc] init];
root_layer1.name = nil;
root_layer1.bounds = CGRectMake(0.000000, 0.000000, 768.000000, 768.000000);
root_layer1.frame = CGRectMake(0.000000, 0.000000, 768.000000, 768.000000);
[someUIView.layer addSublayer:root_layer1];
[root_layer1 release];
CAShapeLayer* root_layer1_layer2 = [[CAShapeLayer alloc] init];
CGMutablePathRef root_layer1_layer2_path_pathref = CGPathCreateMutable();
CGPathMoveToPoint(root_layer1_layer2_path_pathref, NULL, 415.493011, 49.774002);
CGPathAddLineToPoint(root_layer1_layer2_path_pathref, NULL, 448.989014, 153.523010);
CGPathAddCurveToPoint(root_layer1_layer2_path_pathref, NULL, 458.575012, 183.251007, 485.170044, 202.583008, 516.384033, 202.510010);
CGPathAddLineToPoint(root_layer1_layer2_path_pathref, NULL, 625.388062, …
Run Code Online (Sandbox Code Playgroud)

core-graphics objective-c cgpath

0
推荐指数
1
解决办法
1066
查看次数