我使用AVMutableComposition在視頻中使用CATextLayer設置文本,並且正在顯示文本,但我無法在屏幕上設置其位置......使用此代碼文本正在顯示,但它顯示在左側屏幕和被削減一半...如何在iphone中使用CATextLayer設置視頻中的文本位置?
有沒有人幫我弄清楚這個疑難問題真的得到了這裏,而不是擊中能夠找到解決方案..pls幫助我
代碼我使用的是...
AVAssetTrack * clipVideoTrack = [[videoAsset tracksWithMediaType: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];
可以請你給我建議你如何解決這個問題? – 2015-08-03 05:36:21
請在這個鏈接看到我的問題..http://stackoverflow.com/questions/31780060/how-to-set-catextlayer-in-video-according-to-frame – 2015-08-03 06:55:11
請檢查下面給出的答案,並嘗試設置它使用CGPointMake的位置。 – 2015-08-03 11:21:53