- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我们想在我们的 iPhone 应用程序中使用 UITabBar,但有一个异常(exception):我们有一个“同步”按钮,我想在同步操作发生时旋转它。
不幸的是,这意味着必须创建一个自定义标签栏,但这既不是这里也不是那里:我使用 Core Animation 实现的动画看起来很棒。问题是,在设置动画时,它会对屏幕上使用动画的其他所有内容的性能产生不利影响:UITableView 滚动、MKMapView 平移和引脚掉落等。我的测试设备是 iPhone 4。
问题似乎是我如何实现标签栏 - 我想实现与 UITabBar 非常相似的东西,你只需为图标提供 PNG,它使用 alpha channel 创建正常和突出显示状态掩盖背景图像。我用 CALayer 的 mask
属性完成了这个:
// Inside a UIView subclass' init method...
// Create the mask layer by settings its contents as our PNG icon.
CALayer *maskLayer = [CALayer layer];
maskLayer.frame = CGRectMake(0, 0, 31, 31);
maskLayer.contentsGravity = kCAGravityCenter;
maskLayer.contentsScale = [[UIScreen mainScreen] scale];
maskLayer.rasterizationScale = [[UIScreen mainScreen] scale];
maskLayer.contents = (id)symbolImage.CGImage;
maskLayer.shouldRasterize = YES;
maskLayer.opaque = YES;
fgLayer = [[CALayer layer] retain];
fgLayer.frame = self.layer.frame;
fgLayer.backgroundColor = [UIColor colorWithImageNamed:@"tabbar-normal-bg.png"].CGColor;
fgLayer.mask = maskLayer; // Apply the mask
fgLayer.shouldRasterize = YES;
fgLayer.opaque = YES;
[self.layer addSublayer:fgLayer];
(注意:在上面的屏幕截图中,您可以看到我还添加了一个阴影层,但为了简单起见,我从代码中删除了它。我在同步图标设置动画时从同步图标中删除了阴影层,所以它不应该不相关。)
要制作动画,我只需旋转 mask 层:
- (void)startAnimating {
CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath: @"transform"];
CATransform3D transform = CATransform3DMakeRotation(RADIANS(179.9), 0.0, 0.0, 1.0);
animation.toValue = [NSValue valueWithCATransform3D:transform];
animation.duration = 5;
animation.repeatCount = 10000;
animation.removedOnCompletion = YES;
[fgLayer.mask addAnimation:animation forKey:@"rotate"]; // Add animation to the mask
}
所以这一切都很好,除了性能。你可以看到我已经尝试过在 Google 上出现的关于栅格化图层/使它们不透明的提示 - 没有帮助。
我想我已经确定 mask 层是罪魁祸首。当我取出 mask 层并旋转 fgLayer
而不是它的 mask 时,性能非常好,尽管这肯定不是我想要的效果:
如果在应用 mask 时旋转 fgLayer
而不是 mask ,性能也和以前一样差。
因此,如果必须重新合成 mask ,动画的每一帧都会变慢,我是否可以使用任何其他技术来实现类似的效果,从而获得更好的性能?使用路径而不是图像作为 mask 层?或者我是否必须降低到 OpenGL 或其他东西以获得良好的性能?
更新:进一步强化了掩码是减速的想法,我的同事建议尝试旋转一个 CALayer,仅将图像作为内容——与我上面没有掩码的示例非常相似——这样的表现也很好。所以我真的只能做那样的纯色(没有渐变),但这可能是一个很好的临时解决方案。不过,我仍然希望以良好的性能实现旋转蒙版,因此欢迎提出建议:)
最佳答案
布伦特,
为什么需要使用图层蒙版?不能将 mask 层转换为子层吗?您只需要确保您的图像具有正确的 alpha 并且您将使用它的 CGImageRef 作为该层的内容。
还有一点。我还没有弄清楚为什么,但是当我在每一层而不是顶层应用 shouldRasterize 时,我也注意到了性能问题。您可能会看到在 mask 层中删除对 setShouldRasterize:YES 的引用是否有帮助。
关于iphone - Core Animation CALayer mask 动画表现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4520941/
我有两个包含两个接近矩形的形状的蒙版。 面罩示例(黄色): 现在,我要确定其中一个遮罩比另一个遮罩更接近实际矩形。 有可能实现吗? 最佳答案 获取轮廓和(旋转的)矩形边界框之间的面积差。面积差异最小的
我最近从 numpy 1.11 升级到 numpy 1.13 希望摆脱这个屏蔽数组警告,但它仍然存在: MaskedArrayFutureWarning:在具有共享掩码的掩码数组上设置项目不会复制掩码
我需要在sencha中的选项卡面板中添加一个加载掩码,我在 Controller 中通过Ajax请求加载了一个商店,但是在商店加载之前我需要放置一个加载掩码,并且在商店加载之后已加载,我需要将其删除。
我希望能够设置或清除 uintX_t 的(多个)位。 i 是一个运行时变量 (uintX_t)。b 是一个运行时变量 (uintX_t),它被限制为 0 或 1。 mask 是编译时常量。 有没有比以
我有一个处理程序,更像是一个提交按钮。我想掩盖整个页面或该表单以显示等待消息,直到完成其余过程。我做到了,它在FF中有效,但在IE中没有成功,当我执行Ext.getCmp('').body.mask(
我有我使用 Snap SVG 的 JS 代码。在某些时候我使用 element.attr({mask:maskelement}); 在该片段中,element和 maskelement是我的 svg
我需要从图标(.ICO) 文件中获取XOR Mask 和AND Mask。 如果有人可以建议我如何从 Java 执行此操作,那就太棒了。如果没有,您是否知道有任何应用程序可以获取这两个掩码并允许您扔掉
我一直在尝试学习scenekit并完成了一本书,但只有碰撞检测部分不明白,也许是最重要的部分。有类别掩码、共谋掩码和物理体?.contactTestBitMask。 我想创建一个简单的游戏来实现这个目
我在 Canvas 上制作了一个矩形 mask ,我需要 mask 外的任何东西都具有 0.8 的不透明度,因此 mask 外的所有对象都被视为不透明请看一下 fiddle 。 http://jsfi
我有一个包含可滚动内容的 div。我想为其添加一个覆盖内容的颜色 mask ,但不会随内容滚动。 http://jsfiddle.net/6e9t1wt3/1/ *{box-sizing:bord
在我的代码中,我必须选择这两个表达式之一(其中 mask 和 i 是非常数整数 -1 > i & 1) 和 (mask & 1 << i) 哪个更快?,我们在Stack Overflow上找到一个类似
我有一个包含 Image 的 Imageview 。还有一个包含兔子形状的面具形状。我有一个代码可以给出以下结果。 - (UIImage*)mynewmaskImage:(UIImage *)imag
您可能熟悉 enum 位掩码方案,例如: enum Flags { FLAG1 = 0x1, FLAG2 = 0x2, FLAG3 = 0x4, FLAG4 = 0x8
在本文之后,我将尝试实现他们如何计算每个实体的对数概率的平均值(第3.3节)。更具体地说,每个实体的得分计算为其令牌上的日志概率的平均值。。我有一个实体列表和一些提示:。任务是为每个提示找到应该适合的
我正在尝试遮盖比 mask 小的背景图像。背景和蒙版之间的空间显示为黑色。 这是我正在使用的代码: batch.end(); batch.begin(); Gdx
因此,我一直在尝试将背景图像裁剪成圆形 六边形,我发现 webkit 令人惊叹的 mask 图像非常容易地解决了我所有的问题。遗憾的是,它仅适用于 Chrome 和 Safari(当然)。 我如何为非
我有两个Java项目数据服务应用程序和数据报告应用程序,数据服务应用程序生成用于某些处理和数据报告应用程序的某些数据应该使用数据服务应用程序来使用它生成的数据来生成一些报告,这两个应用程序都应该构建为
我有一个带有绿色背景的简单 Activity ,我正在尝试提供一个带有透明圆形区域的红色叠加层。这是我要实现的效果: Expected Image 根据我在网上找到的代码,我看到的是这样的: Resu
我关注了这个link创建一个名为 mask 的自定义操作。tensorflow op的主体是 def tf_mask(x, labels, epoch_, name=None): # add "la
正如标题所说,我有 self.view,我将其添加到它的 mask 中(link) 属性另一个 View ,但是当我使用 addSubview 添加更多 View 到 self.view 时,掩码被删
我是一名优秀的程序员,十分优秀!