我正在尝试使用 AVComposition 创建电影生成应用程序,但在制作标题框架时遇到了麻烦。每个帧实际上是一个 calayer,标题层位于其他帧的顶部。
标题(文本)需要是透明的黑色背景,以便他们可以在标题文本字母下看到第一个内容框架的某些部分。
我搜索了大多数关于 calayer 面具的文章,但没有任何帮助。我认为这篇文章(如何在 IOS 的 UIView 中仅使文本/标题覆盖的部分透明)很有帮助,并且像 Dave 的方式一样编码,但只有白屏。
这是我所做的:
// create UILabel from the title text
CGRect rectFrame = CGRectMake(0, 0, videoSize.width, videoSize.height);
UILabel *lbTitle = [[UILabel alloc] initWithFrame:rectFrame];
lbTitle.text = self.titleText;
lbTitle.font = [UIFont fontWithName:@"Helvetica" size:60];
lbTitle.textColor = [UIColor blackColor];
lbTitle.backgroundColor = [UIColor whiteColor];
// get title image and create mask layer
UIGraphicsBeginImageContextWithOptions(lbTitle.bounds.size, TRUE, [[UIScreen mainScreen] scale]);
[lbTitle.layer renderInContext:UIGraphicsGetCurrentContext()];
CGImageRef viewImage = [UIGraphicsGetImageFromCurrentImageContext() CGImage];
UIGraphicsEndImageContext();
CALayer *maskLayer = [CALayer layer];
maskLayer.contents = (__bridge id)viewImage;
maskLayer.frame = rectFrame;
// create title background layer and set mastLayer as mast layer of this layer
// this layer corresponds to "UIView's layer" in Dave's method
CALayer *animatedTitleLayer = [CALayer layer];
animatedTitleLayer.backgroundColor = [UIColor whiteColor].CGColor;
animatedTitleLayer.mask = maskLayer;
animatedTitleLayer.frame = rectFrame;
...
[view.layer addSubLayer:animatedTitleLayer];
这里我使用animatedTitleLayer作为标题背景(黑色背景),但我看到的是白屏。
任何人都可以帮助我吗?提前致谢。