如何根据帧在视频中设置CATextLayer?
How to set CATextLayer in video according to frame?
我尝试了很多想法,但还没有成功,我的问题是我有一个视频,我提供了一种在视频上写文字的功能,drag/drop 现在我想在视频上写文字在用户设置的适当位置的视频上设置 CATextlayer 但它没有显示在适当的位置所以请帮助我。
这是我为此使用的代码。
CATextLayer *titleLayer = [CATextLayer layer];//<========code to set the text
titleLayer.string = self.strText;
titleLayer.font = (__bridge CFTypeRef)(self.fonts);;
titleLayer.fontSize = titleLayer.fontSize;
titleLayer.position = CGPointMake (titleLayer.fontSize,titleLayer.fontSize);
//?? titleLayer.shadowOpacity = 0.5;
titleLayer.alignmentMode = kCAAlignmentCenter;
titleLayer.bounds = CGRectMake(self.rectText.origin.x,self.rectText.origin.y-52, 480, 480); //You may need to adjust this for proper display
[titleLayer setBackgroundColor:[UIColor redColor].CGColor];
[parentLayer addSublayer:titleLayer]; //ONLY IF WE ADDED TEXT
你的代码看起来不错,但不确定提供的框架是错误的还是正确的。如果您提供了正确的框架,请在最后添加此代码:-
[titleLayer display];
现在可以使用了!
解决了这个问题,请看我下面的代码。这与 video.
配合使用效果很好
CATextLayer *titleLayer = [CATextLayer layer];
titleLayer.string = self.strText;
titleLayer.font = (__bridge CFTypeRef)(self.fonts);
titleLayer.fontSize = fontsize;
titleLayer.masksToBounds = NO;
titleLayer.foregroundColor = self.textColor.CGColor;
titleLayer.alignmentMode = kCAAlignmentCenter;
//[self.txtVideoText setBackgroundColor:[UIColor colorWithHue:255.0/255.0 saturation:255.0/255.0 brightness:255.0/255.0 alpha:0.4]];
//[self setAnchorPoint:self.txtVideoText.layer.anchorPoint forView:self.txtVideoText layer:titleLayer];
titleLayer.anchorPoint = CGPointMake(0.5, 0.5);
titleLayer.frame = CGRectMake(xx,-(yy-CGRectGetHeight(self.viewHeader.frame)), 480, 480); //You may need to adjust this for proper display
[parentLayer addSublayer:titleLayer]; //ONLY IF WE ADDED TEXT
解决了这个问题,请看我下面的代码。这与视频
配合得很好
CGFloat stickerX = (videoSize.width * (newsticker.frame.origin.x+imageView2.frame.origin.x))/_StickerView.frame.size.width;
CGFloat stickerY = (videoSize.height * (newsticker.frame.origin.y+imageView2.frame.origin.y))/_StickerView.frame.size.height;
titleLayer.frame = CGRectMake(stickerX,-(StickerY-CGRectGetHeight(self.viewHeader.frame)), 480, 480); //You may need to adjust this for proper display
我尝试了很多想法,但还没有成功,我的问题是我有一个视频,我提供了一种在视频上写文字的功能,drag/drop 现在我想在视频上写文字在用户设置的适当位置的视频上设置 CATextlayer 但它没有显示在适当的位置所以请帮助我。
这是我为此使用的代码。
CATextLayer *titleLayer = [CATextLayer layer];//<========code to set the text
titleLayer.string = self.strText;
titleLayer.font = (__bridge CFTypeRef)(self.fonts);;
titleLayer.fontSize = titleLayer.fontSize;
titleLayer.position = CGPointMake (titleLayer.fontSize,titleLayer.fontSize);
//?? titleLayer.shadowOpacity = 0.5;
titleLayer.alignmentMode = kCAAlignmentCenter;
titleLayer.bounds = CGRectMake(self.rectText.origin.x,self.rectText.origin.y-52, 480, 480); //You may need to adjust this for proper display
[titleLayer setBackgroundColor:[UIColor redColor].CGColor];
[parentLayer addSublayer:titleLayer]; //ONLY IF WE ADDED TEXT
你的代码看起来不错,但不确定提供的框架是错误的还是正确的。如果您提供了正确的框架,请在最后添加此代码:-
[titleLayer display];
现在可以使用了!
解决了这个问题,请看我下面的代码。这与 video.
配合使用效果很好CATextLayer *titleLayer = [CATextLayer layer];
titleLayer.string = self.strText;
titleLayer.font = (__bridge CFTypeRef)(self.fonts);
titleLayer.fontSize = fontsize;
titleLayer.masksToBounds = NO;
titleLayer.foregroundColor = self.textColor.CGColor;
titleLayer.alignmentMode = kCAAlignmentCenter;
//[self.txtVideoText setBackgroundColor:[UIColor colorWithHue:255.0/255.0 saturation:255.0/255.0 brightness:255.0/255.0 alpha:0.4]];
//[self setAnchorPoint:self.txtVideoText.layer.anchorPoint forView:self.txtVideoText layer:titleLayer];
titleLayer.anchorPoint = CGPointMake(0.5, 0.5);
titleLayer.frame = CGRectMake(xx,-(yy-CGRectGetHeight(self.viewHeader.frame)), 480, 480); //You may need to adjust this for proper display
[parentLayer addSublayer:titleLayer]; //ONLY IF WE ADDED TEXT
解决了这个问题,请看我下面的代码。这与视频
配合得很好CGFloat stickerX = (videoSize.width * (newsticker.frame.origin.x+imageView2.frame.origin.x))/_StickerView.frame.size.width;
CGFloat stickerY = (videoSize.height * (newsticker.frame.origin.y+imageView2.frame.origin.y))/_StickerView.frame.size.height;
titleLayer.frame = CGRectMake(stickerX,-(StickerY-CGRectGetHeight(self.viewHeader.frame)), 480, 480); //You may need to adjust this for proper display