问题标签 [calayer]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
3 回答
5172 浏览

iphone - 观察 CALayer 中的动画属性变化

我有一个CABasicAnimation动画一个CALayer例如的属性bounds.origin。我希望能够观察到属性随时间的变化,但还没有真正找到一种 100% 有效的方法。

  1. presentationLayer我尝试在的键路径上使用 KVO(键值观察)bounds.origin。系统抱怨对象在其观察者被释放之前被释放,导致我认为表示层只是暂时的。作为键路径观察presentationLayer.bounds.origin是行不通的。

  2. 我尝试在另一个图层上创建一个属性并为其设置动画,例如通过声明并在该图层上@property制作它。@dynamic然而,这个新属性只有在访问表示层时(例如在动画结束时)才会改变,它似乎在动画运行时不会更新。

  3. needsDisplayForKey在#2 中使用了属性,它确实会在动画期间触发更新,但是对于这些问题:

    • 它仅在CALayer具有非零帧时才有效。由于该层可能是 CAShapeLayer 或子类,因此它可能具有零帧。
    • 看起来它触发setNeedsDisplay了该层,但由于我实际上并没有绘制该层,只监视属性更改,所以我不想让它重绘。
  4. 我尝试安排一个NSTimer, 并在计时器回调样本中presentationLayer. 这也适用,但对于这些问题:

    • 计时器可能与动画更新稍微不同步。
    • 由于有时原始动画会被另一个动画抢占,因此很难真正让计时器在动画运行时触发,并且仅在动画运行时触发。

有什么建议么?所有这些都将在 iPhoneOS 3.0/3.1 上进行。

0 投票
2 回答
1524 浏览

objective-c - 核心动画层中的 webview

我想在 CALayer 中创建一个 webView。也许这太微不足道了,但我刚刚进入 CA。有人可以帮忙吗?

欢呼罗恩

0 投票
4 回答
5531 浏览

iphone - 为 CALayer 带来SubviewToFront

我想知道是否有办法将图层置于其他视图图层之上。像上课一样bringSubviewToFront的东西。UIView我认为它可以通过zPosition属性来完成,CALayer但这意味着我必须检查zPosition所有层,然后设置适当的值。

提前致谢。

0 投票
3 回答
18171 浏览

iphone - 复合颜色:iPhone 上的 CALayer 和混合模式

我正在尝试在 iphone 上使用核心图像。我可以使用石英合成我的颜色来绘制一个 uiview,但我想将每个组件分成CALayer(UIview 消耗更多资源)。

所以我有一个白色蒙版,我想用它来过滤背景位图,我想尝试不同的混合模式。不幸的是,这些图层只是“添加”了它们的颜色。

这是我的代码:

这是drawrect我使用 CALayer 的主视图代码:

有什么不对?

0 投票
1 回答
566 浏览

iphone - iPhone图层混乱

我正在尝试做一些应该非常简单的事情。我想为我的一个视图添加渐变。我可以将它添加到 self.view,但不能添加到 viewWithGradient。这是代码:

viewWithGradient 是我在 viewController (self.view) 内的主视图中的一个小视图。这个 viewWithGradient 只有一个其他视图。它是一个 UILabel,只占 viewWithGradient 面积的一半左右。它具有透明背景,但标签将其文本绘制为白色。我需要让渐变在 UILabel 下,而不是在 self.view 上,在 UILabel 上。

我目前怀疑我的框架/边界可能会使渐变脱离屏幕。有人看到我缺少的东西吗?这似乎是最简单的 CALayer 用法,我花了太多时间在上面。

0 投票
1 回答
707 浏览

iphone - iphone 2d绘图新手问题

我已经为 iphone 编程几个月了,商店里已经有 3 个应用程序了。

但是,我还没有在平台上进行任何类型的图形编程。

鉴于我正计划启动我的第 5 个应用程序(第 4 个应用程序正在 Apple 的审查中),我想询问一些关于在哪里获取此信息的指示(谷歌搜索了一段时间,但没有与我正在寻找的内容相匹配)

我需要创建一个应用程序,我可以在其中将一些形状从菜单(矩形、圆形、正方形,然后是一些复杂的形状)“拖放”到主窗口上。

这个想法是用户可以拖动它们。但是,我希望它们相互“捕捉”(有点像在 CAD 包中,一个圆的边缘有象限,可以捕捉到绘图中的任何其他几何实体)。

因此,如果我在屏幕左侧有一个圆圈,在右侧有一个矩形,然后我移动圆圈,如果我碰到矩形边缘,它将停止向右移动。不是完全停止,而是对运动的连续性给予某种“阻力”。

另外,如果我有几张重叠的图纸,有没有办法“划分”它们(任何重叠都会成为其自身的形状,但会从构成重叠的任何其他形状中移除)?

这样做的原因是我需要计算绘图的面积(以及其他属性)

我正在考虑 CALayer 1, 2, 3,..., n 在另一个之上,每个都有一个绘图(使用 CGPath?),可能会或可能不会与其他人重叠。

然后我需要以某种方式获取单个 CALayer 上所有这些“投影”的信息。

我在这里一无所知。

我应该研究 Quartz2D 吗?CALayer 和 CGPath 是否足够?

这不是为了游戏。只是我想到的一个工程应用程序。

任何帮助表示赞赏。

问候 dh

0 投票
1 回答
4539 浏览

core-animation - CALayer 渲染上下文

我用

成功了,但是我使用“renderInContext:context”从上下文中获取CGImage,我发现图像效果没有改变!

我怎样才能从 CALayer 得到这个效果图?

0 投票
2 回答
1102 浏览

iphone - iPhone layer management - best practice

Louis - Thanks for your input. Here is what I did, and my current issues, which i don't understand.

The menus (2) are UIImageViews that respond to touch. Each is it's own class. The 'sprites' as you called them also respond to touch.

In the .m where I add the menus and sprites to the layer, I created two container layers, via this code: menuContainer = [CALayer layer].

I ordered them with the menuContainer above the spriteContainer. Now, the sprites do move below the menus - great! But in the process, the sprites stopped responding to touch (I can understand this as they are below the menuContainer layer), and the menus stopped responding to touch as well (don't get that). Continuing to confuse the situation, a layer added to the menuContainer that responds to a multitouch gesture by popping up a slider still reads the multitouch and pops up the slider, but I can't slide the slider. This has me thoroughly confounded.

Thanks.

My app is building a background layer, then building some menu layers that should always be at the top. After this, I add many moving layers and remove many moving layers very quickly.

My problem is I want my menu layers (there are 4) to always be in front of the other layers. I have thought of building a layer hiearchy and using the insertsublayer: atindex: method, making my menus a notional index of 1000, and inserting the multitude of moving layers at a lower index, like 200. If I insert one layer at 200 and then the next at 200, does the first layer that was assigned to 200 get shifted (to 201) or does it get blown away?

I have tried inserting the layers with the insertsublayer: below:, but that does not give me the desired results.

Thanks for the help.

0 投票
2 回答
1885 浏览

iphone - CALayer insertSublayer: atindex: 是否具有破坏性?

文档不清楚使用 insertSublayer:abc.layer atindex:xy 时当前 atindex:xy 层会发生什么。我的实验结果好坏参半。我的理解是索引 0 离用户最远(所有其他层都在该层之上)。

如果我在 index:0 处调用 insertSublayer:abc.layer,并且 def.layer 已经在 index:0 处,def.layer 会被破坏还是转移到 index:1?

谢谢。

0 投票
1 回答
436 浏览

iphone - 无法看到从单独的 animationDidStop 开始的第二个动画

我在让 CoreAnimation 在 iPhone 模拟器上连续执行多个动画时遇到了一些问题。我的应用程序中有很多层需要制作动画——这些层都是与我的应用程序中的 UIView 关联的层的子层。在为第一个子层的位置设置动画后(使用显式动画 - CAKeyFrameAnimation),我在 animationDidStop 委托方法中执行以下操作:

  1. 我从其超层中删除该层
  2. 我启动一个 CATransaction 来同时为其他 2 个子图层的位置设置动画 - 这些图层也通过添加到各个图层的单独 CAKeyframeAnimations 显式设置动画。
  3. 然后我重用具有不同内容的第一层并将其添加回超级层的单独位置(故意不动画)。

当我运行我的应用程序时,我看到第一个动画出现,然后层被删除,层被添加回新位置的新内容,但我在第 2 步中从未看到 2 层的动画。有趣的是,我为事务中的 2 个动画层中的每一层获取 animationDidStop 调用。由于我接到这些电话,因此动画似乎正在发生,但动画不会出现在屏幕上。如果我没有正确设置并且看到相同的结果,我还尝试删除事务。

是否可以以这种方式将多个动画链接在一起?

非常感谢任何见解或建议。在此先感谢您的帮助。