2
私はRECTをクリッピング属性付き文字列を描きたい、と私はObjective-Cで記述された機能を発見し、Swift 3でCFDictionaryCreateを使用するには?
CFDictionaryRef PINCHFrameAttributesCreateWithClippingRect(CGRect clippingRect, CGAffineTransform transform)
{
CGPathRef clipPath = CGPathCreateWithRect(clippingRect, &transform);
CFDictionaryRef options;
CFStringRef keys[] = {kCTFramePathClippingPathAttributeName};
CFTypeRef values[] = {clipPath};
CFDictionaryRef clippingPathDict = CFDictionaryCreate(NULL,
(const void **)&keys, (const void **)&values,
sizeof(keys)/sizeof(keys[0]),
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
CFTypeRef clippingArrayValues[] = { clippingPathDict };
CFArrayRef clippingPaths = CFArrayCreate(NULL, (const void **)clippingArrayValues, sizeof(clippingArrayValues)/sizeof(clippingArrayValues[0]), &kCFTypeArrayCallBacks);
CFStringRef optionsKeys[] = {kCTFrameClippingPathsAttributeName};
CFTypeRef optionsValues[] = {clippingPaths};
options = CFDictionaryCreate(NULL, (const void **)&optionsKeys, (const void **)&optionsValues,
sizeof(optionsKeys)/sizeof(optionsKeys[0]),
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
CFRelease(clippingPathDict);
CFRelease(clippingPaths);
CGPathRelease(clipPath);
return options;
}
しかし、私はスウィフト3でそれを翻訳することができなかった、誰も私を助けることができますか?
// 私はコードをbelowing試してみました、それはコンパイルおよび実行されますが、テキストはクリップを行いません。
let keys: [CFString] = [kCTFrameClippingPathsAttributeName]
let values: [CFTypeRef] = [clipPath]
let keysPointer = UnsafeMutablePointer<UnsafeRawPointer?>.allocate(capacity: keys.count)
keysPointer.initialize(to: keys)
let valuesPointer = UnsafeMutablePointer<UnsafeRawPointer?>.allocate(capacity: values.count)
valuesPointer.initialize(to: values)
let options = CFDictionaryCreate(kCFAllocatorDefault, keysPointer, valuesPointer, 1, nil, nil)
let framesetter = CTFramesetterCreateWithAttributedString(attributedSring)
let frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, attributedSring.length), rectPath.cgPath, options)
CTFrameDraw(frame, context)