标签: catextlayer

旋转后CATextLayer模糊文本

我有一个相关的问题的问题
我已经设置contentsScale和文字后,看起来不错,但如果我申请的3D旋转变换文字出来模糊.

图像在这里

初始化代码

    // init text
    textLayer_ = [CATextLayer layer];
    …
    textLayer_.contentsScale = [[UIScreen mainScreen] scale];

    // init body path
    pathLayer_ = [CAShapeLayer layer];
    …
    [pathLayer_ addSublayer:textLayer_];
Run Code Online (Sandbox Code Playgroud)

轮换代码

    // make the mirror
    pathLayer_.transform = CATransform3DRotate(pathLayer_.transform, M_PI, 0, 1, 0);
    textLayer_.transform = CATransform3DRotate(textLayer_.transform, M_PI, 0, 1, 0);
    [textLayer_ setNeedsDisplay];
Run Code Online (Sandbox Code Playgroud)

为了测试我在初始化期间单独旋转文本.

    // init text
    textLayer_ = [CATextLayer layer];
    …
    textLayer_.transform = CATransform3DRotate(textLayer_.transform, M_PI, 0, 1, 0);
    textLayer_.contentsScale = [[UIScreen mainScreen] scale];
Run Code Online (Sandbox Code Playgroud)

可以旋转文本并在此处保持清晰
图像

core-animation transform ios retina-display catextlayer

3
推荐指数
1
解决办法
2901
查看次数

如何处理CATextLayer在UILabel中显示与系统字体相同的字体?

当我使用时UILabel,我将系统字体设置为:

label.font = UIFont.systemFontOfSize(18, weight: UIFontWeightMedium)
Run Code Online (Sandbox Code Playgroud)

现在我尝试使用CATextLayer和我在线搜索,发现iOS 9的系统字体是San Francisco和字体名称.SFUIText-Medium,所以我尝试将字体名称设置为:

textLayer = CATextLayer() 
textLayer.font = CTFontCreateWithName(".SFUIText-Medium", 18, nil)
Run Code Online (Sandbox Code Playgroud)

但是,设备屏幕上显示的字体UILabelCATextLayer上面说明的不同.CATextLayer这里使用的字体名称是什么,这样我可以使用完全相同的字体显示UILabel

objective-c catextlayer swift

3
推荐指数
1
解决办法
2462
查看次数

子层上的CAlayer变换用手势闪烁(ipad)

我有一个包含很少其他子层的CALayer(实际上是CATextLayer)

当用户在ipad上执行常规手势但我似乎无法正常工作时,我想在该图层上应用一些转换.使用CALayer的目的是仅将转换应用于该层,以便使用相同的转换同时影响我的所有子textLayer.

发生的事情是转换似乎在前一个位置和当前位置之间闪烁.我并没有真正得到可能存在的问题......例如,当我做一个2指平移手势时,CaTextLayer会在我的手势中一直闪烁,最后它们都被正确放置在新的平移位置.

所以一切似乎工作得很好,除了闪烁的东西困扰我很多.

我需要设置一些我不知道的属性吗?我在想它可能与边界和框架有关......

这是我创建CATextLayer的方法(这只在创建时完成一次,并且正常工作):

_textString = [[NSString alloc] initWithString: text];   
_position = position;

attributedTextLayer_ = [[CATextLayer alloc] init];
attributedTextLayer_.bounds = frameSize;

//.. Set the font 

attributedTextLayer_.string = attrString;
attributedTextLayer_.wrapped = YES;

CFRange fitRange;
CGRect textDisplayRect = CGRectInset(attributedTextLayer_.bounds, 10.f, 10.f);
CGSize recommendedSize = [self suggestSizeAndFitRange:&fitRange 
                                      forAttributedString:attrString 
                                                usingSize:textDisplayRect.size];

[attributedTextLayer_ setValue:[NSValue valueWithCGSize:recommendedSize] forKeyPath:@"bounds.size"];
attributedTextLayer_.position = _position;
Run Code Online (Sandbox Code Playgroud)

这就是我将它们添加到我的Super CALayer中的方法

[_layerMgr addSublayer:t.attributedTextLayer_];

[[_drawDelegate UI_GetViewController].view.layer addSublayer:_layerMgr];
Run Code Online (Sandbox Code Playgroud)

以下是我如何应用我的转换:

_layerMgr.transform = CATransform3DMakeAffineTransform(_transform);

calayer ipad catransform3d catransaction catextlayer

1
推荐指数
1
解决办法
1251
查看次数

CATextLayer 忽略 NSMutableParagraphStyle

我想用NSMutableAttributedString文字来绘制CATextLayer文字。我尝试将属性设置为NSMutableAttributedString通过的字体和字体颜色,[attrString setAttributes:attributes range:range];NSMutableParagraphStyle忽略中的所有属性。

let str = "I want to use NSMutableAttributedString to draw the text on the CATextLayer with the text. I try set attributes to the like font and fontcolor of the NSMutableAttributedString through the [attrString setAttributes:attributes range:range]; but all attributes in the NSMutableParagraphStyle are ignored."
    let att = NSMutableAttributedString(string: str)
    let paragraphStyle = NSMutableParagraphStyle()
    paragraphStyle.lineSpacing = 12
    att.addAttribute(NSParagraphStyleAttributeName, value: paragraphStyle, range: NSMakeRange(0, str.characters.count))
let contentLayer = initTextLayer("", andFontSize: …
Run Code Online (Sandbox Code Playgroud)

catextlayer

1
推荐指数
1
解决办法
359
查看次数

是否可以将 UILabel 或 CATextLayer 添加到 Swift 中的 CGPath,类似于 Photoshop 的类型到路径功能?

我想添加文本,无论是 aUILabel还是CATextLayera CGPath。我意识到此功能背后的数学相当复杂,但想知道 Apple 是否提供了开箱即用的此功能,或者是否有开源 SDK 可以在 Swift 中实现这一点。谢谢!

例子:

calayer uilabel cgpath catextlayer swift

1
推荐指数
1
解决办法
272
查看次数

CATextLayer位置和变换问题

我正在尝试构建一个类似附加圆形图像的控件,其中多个段的每个部分的空间相等。段数可以根据提供的数组而改变。

到目前为止,我已经使用 CAShapeLayer 和 UIBezierPath 开发了这个。还在每个形状图层的中心添加了文本。到目前为止,我已经添加了用于生成此控件的代码。

在此输入图像描述

let circleLayer = CALayer()
func createCircle(_ titleArray:[String]) {
     update(bounds: bounds, titleArray: titleArray)
     containerView.layer.addSublayer(circleRenderer.circleLayer)
}


 func update(bounds: CGRect, titleArray: [String]) {
        let position = CGPoint(x: bounds.width / 2.0, y: bounds.height / 2.0)
        circleLayer.position = position
        circleLayer.bounds = bounds
        update(titleArray: titles)
    }

func update(titleArray: [String]) {
   let center = CGPoint(x: circleLayer.bounds.size.width / 2.0, y: circleLayer.bounds.size.height / 2.0)
   let radius:CGFloat = min(circleLayer.bounds.size.width, circleLayer.bounds.size.height) / 2
   let segmentSize = CGFloat((Double.pi*2) / Double(titleArray.count))
   
   for i in 0..<titleArray.count {
       let …
Run Code Online (Sandbox Code Playgroud)

cashapelayer ios catextlayer quartz-core swift

0
推荐指数
1
解决办法
922
查看次数