Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
355 views
in Technique[技术] by (71.8m points)

ios - How to set CATextLayer in video according to frame?

I have try many think but no success yet, My question is that I Have one video on that I was provide a functionality to write text over the video and drag/drop that text over the video now I wand to set CATextlayer on video with propper position which was set by user but its not display on proper position so please help me.

This is my code which was I used for this.

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Your code seems fine, but not sure if the frame provided is wrong or right. If you have provided the right frame then add this code, in the end:-

[titleLayer display];

It will work now!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...