【问题标题】:CATextLayer not visible on video in iOS7CATextLayer 在 iOS7 的视频中不可见
【发布时间】:2013-11-05 15:25:47
【问题描述】:

我正在开发一个视频应用程序,该应用程序使用 .mov 资源作为背景并使用 CATextLayer 作为学分生成学分剪辑。该代码在 iOS 5 和 6 中有效,但在 iOS 7 中无效 - 即:生成了剪辑但不显示文本。

我已尝试使用此问题 (How can I add overlay text on a video, then re-encode it?) 答案中的代码,但 CATextLayer 中的文本仍未显示。

为什么 iOS 7 的行为会有所不同,我怎样才能让它工作?

【问题讨论】:

  • 我尝试解决了 2 天,但无法正常工作
  • 只有当我将前景色设置为黄色并将背景色设置为白色时才有效。奇怪!!!!
  • @Rob VS,很有趣的人通常会感谢问题回答者,但我常常非常感谢首先提出问题的人。感谢您让我免于 30 分钟的挠头!

标签: iphone objective-c ipad ios7 video-editing


【解决方案1】:

2天后解决这个问题

CATextLayer *text = [CATextLayer layer];
text.string = @"Your Text";
text.frame = CGRectMake(0, 0, 320, 50);
CGFontRef font = CGFontCreateWithFontName((CFStringRef)@"HelveticaNeue-UltraLight");
text.font = font;
text.fontSize = 20;
text.foregroundColor = [UIColor whiteColor].CGColor;
[text display];
[aLayer addSublayer:text];
[aLayer display];

秘诀就是调用[CALayer display]方法

【讨论】:

  • 天哪!! [CALayer display] 和 [CATextLayer display] 成功了。我刚刚将我的代码转换为模仿 Apple 的 AVSimpleEditoriOS 示例代码,但它仍然无法正常工作(几乎唯一的差异是我添加标题的 .mov 文件)。顺便说一句,Apple 的代码不调用“显示”。谢谢老兄!!
  • 我建议使用 displayIfNeeded 而不是 display,因为 display 不应该被直接调用。
  • 谢谢。在我的头撞在桌子上太久之后,这神奇地为我解决了这个问题。
  • 哈哈,3 年过去了,这仍然在拯救世界!谢谢@MAMN84
  • 拯救我的白天和黑夜:)。谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-28
  • 1970-01-01
相关资源
最近更新 更多