我在使用 AVMutableComposition 的视频中使用 CATextLayer 设置文本,并且正在显示文本,但我无法在屏幕上设置其位置...使用此代码正在显示文本,但它显示在屏幕的左侧并被减半...
有没有人可以帮我解决这个问题。我真的被击中了,找不到解决方案..请帮帮我
我使用的代码是...
AVAssetTrack *clipVideoTrack = [[videoAsset trackingWithMediaType: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];