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

标签 iphone ios ios4 cocos2d-iphone iphone-sdk-3.0

我正在使用 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/

相关文章:

iphone - 是否有 APN 的替代方案

iphone - 如何在抖动效果上制作动画图像?

ios - iOS 中的 TCP 套接字编程。服务器客户端响应

ios - iOS BLE 应用程序中的重新连接过程

cocoa-touch - 测试应用内购买时使用哪个帐户?

iphone - NSURLConnection sendSynchronousRequest - 后台到前台

iphone - 以编程方式为网格中的单元格着色

iphone - 编辑后将实体保存在核心数据中

ios - 使用自动布局时无需任何理由即可调整ULabel的大小

ios - 在 10 秒内向对象发送消息