gpt4 book ai didi

iphone - 如何在iPhone中使用CATextLayer设置视频中的文本位置?

转载 作者:行者123 更新时间:2023-11-29 03:59:02 26 4
gpt4 key购买 nike

我正在使用 AVMutableComposition 的视频中使用 CATextLayer 设置文本,并且文本正在显示,但我无法设置其在屏幕上的位置...使用此代码,文本正在显示,但它显示在左侧屏幕被切掉一半...

有没有人可以帮我解决这个问题。我真的很困惑,无法找到解决方案..请帮助我

我使用的代码是...

AVAssetTrack *clipVideoTrack = [[videoAsset trackWithMediaType:AVMediaTypeVideo] objectAtIndex:0];

[compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, videoAsset.duration) ofTrack:clipVideoTrack atTime:kCMTimeZero error:nil];

[compositionVideoTrack setPreferredTransform:[[[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] preferredTransform]];

CGSize videoSize = [clipVideoTrack naturalSize];


UIImage *myImage = [UIImage imageNamed:[arrClipArt objectAtIndex:selectedClipArt.tag-200]];//<=======================code to set the Image using CALayer
CALayer *aLayer = [CALayer layer];
aLayer.contents = (id)myImage.CGImage;
aLayer.frame = CGRectMake(selectedClipArt.frame.origin.x-imgMovieThumbnail.frame.origin.x, selectedClipArt.frame.origin.y-imgMovieThumbnail.frame.origin.y, 400, 400);
aLayer.opacity = 1.0;
CALayer *parentLayer = [CALayer layer];
CALayer *videoLayer = [CALayer layer];
parentLayer.frame = CGRectMake(0, 0, videoSize.width, videoSize.height);
videoLayer.frame = CGRectMake(0, 0, videoSize.width, videoSize.height);
[parentLayer addSublayer:videoLayer];
[parentLayer addSublayer:aLayer];

CATextLayer *titleLayer = [CATextLayer layer];//<========code to set the text
titleLayer.string = txtIntro.text;
titleLayer.font = (__bridge CFTypeRef)(txtFont.text);
titleLayer.fontSize = 100;
//?? titleLayer.shadowOpacity = 0.5;
titleLayer.alignmentMode = kCAAlignmentCenter;
titleLayer.bounds = CGRectMake(400,0, 600, videoSize.height/2); //You may need to adjust this for proper display

//titleLayer.frame=CGRectMake(100, 100, 50, 30); [parentLayer addSublayer:titleLayer];

最佳答案

尝试设置 titleLayer 的位置。

titleLayer.position = CGPointMake (100,100);

titleLayer.frame 确实对我有用。

关于iphone - 如何在iPhone中使用CATextLayer设置视频中的文本位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16117684/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com