【问题标题】:How to set the text position in video using CATextLayer in iphone?如何在 iphone 中使用 CATextLayer 设置视频中的文本位置?
【发布时间】:2013-04-13 14:49:56
【问题描述】:

我在使用 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];

【问题讨论】:

  • 你能建议我如何解决这个问题吗?
  • 请在此链接上查看我的问题..stackoverflow.com/questions/31780060/…
  • 请检查下面给出的答案并尝试使用 CGPointMake 设置它的位置。
  • 感谢您的回复,问题已解决。
  • 你设置了位置或边界吗?

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


【解决方案1】:

尝试设置titleLayer的位置。

titleLayer.position = CGPointMake (100,100);

titleLayer.frame 确实对我有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-25
    • 1970-01-01
    • 1970-01-01
    • 2013-11-28
    • 1970-01-01
    • 1970-01-01
    • 2020-07-30
    • 1970-01-01
    相关资源
    最近更新 更多