How to set CATextLayer in video according to frame?
Asked Answered
A

3

1

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
Avram answered 3/8, 2015 at 5:35 Comment(0)
A
0

Solved the issue see my below code. This was working fine with 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
Avram answered 3/8, 2015 at 11:53 Comment(0)
S
0

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!

Streamway answered 3/8, 2015 at 5:44 Comment(1)
Not working, I have test this in iPhone 5, my video screen is square 320*320 and video size is 480*480, se please suggest if we need more some thing to add.Avram
A
0

Solved the issue see my below code. This was working fine with 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
Avram answered 3/8, 2015 at 11:53 Comment(0)
U
0

Solved the issue see my below code. This was working fine with video

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
Underexpose answered 14/7, 2016 at 9:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.