AVCompositionを使って動画生成アプリを作ろうとしていますが、タイトルフレームの作り方に困っています。各フレームは実際にはキャレイヤーであり、タイトル レイヤーは他のフレームの上にあります。
タイトル (テキスト) は、タイトル テキスト文字の下に最初のコンテンツ フレームの一部が見えるように、黒い背景で透明にする必要があります。
カレイヤーマスクに関するほとんどの記事を検索しましたが、何も役に立ちませんでした. この記事 ( 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をタイトルの背景(黒背景)として使用しましたが、表示されるのは白い画面です。
誰でも私を助けることができますか?前もって感謝します。