要改變CATextLayer的字符串屬性時禁用煩人(模糊)的動畫,你可以這樣做:
class CANullAction: CAAction {
private static let CA_ANIMATION_CONTENTS = "contents"
@objc
func runActionForKey(event: String, object anObject: AnyObject, arguments dict: [NSObject : AnyObject]?) {
// Do nothing.
}
}
,然後用它像這樣(不要忘了正確設置你的CATextLayer ,例如正確的字體等):
caTextLayer.actions = [CANullAction.CA_ANIMATION_CONTENTS: CANullAction()]
你可以看到我的CATextLayer的完整安裝位置:
private let systemFont16 = UIFont.systemFontOfSize(16.0)
caTextLayer = CATextLayer()
caTextLayer.foregroundColor = UIColor.blackColor().CGColor
caTextLayer.font = CGFontCreateWithFontName(systemFont16.fontName)
caTextLayer.fontSize = systemFont16.pointSize
caTextLayer.alignmentMode = kCAAlignmentCenter
caTextLayer.drawsAsynchronously = false
caTextLayer.actions = [CANullAction.CA_ANIMATION_CONTENTS: CANullAction()]
caTextLayer.contentsScale = UIScreen.mainScreen().scale
caTextLayer.frame = CGRectMake(playbackTimeImage.layer.bounds.origin.x, ((playbackTimeImage.layer.bounds.height - playbackTimeLayer.fontSize)/2), playbackTimeImage.layer.bounds.width, playbackTimeLayer.fontSize * 1.2)
uiImageTarget.layer.addSublayer(caTextLayer)
caTextLayer.string = "The text you want to display"
現在,只要你想你=可以更新caTextLayer.string多)
通過this啓發,並this回答。
你可以在下一次運行循環中完成它:'dispatch_after(dispatch_time(DISPATCH_TI ME_NOW,(int64_t)(delay * NSEC_PER_SEC)),dispatch_get_main_queue(),^ { });' – 2015-06-17 14:04:20
我在下面找到了很多答案爲我工作。此外,Apple還提供了[更改圖層的默認行爲](https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CoreAnimation_guide/ReactingtoLayerChanges/ReactingtoLayerChanges.html)文檔,該文檔描述了隱式行爲決策過程詳情。 – 2015-10-26 16:41:44