2016-10-20 13 views
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) 

答えて

0

はスウィフト辞書を構築し、その後CFDictionaryにキャスト。例:ここ

let d = [ 
     kCGImageSourceShouldAllowFloat as String : true as NSNumber, 
     kCGImageSourceCreateThumbnailWithTransform as String : true as NSNumber, 
     kCGImageSourceCreateThumbnailFromImageAlways as String : true as NSNumber, 
     kCGImageSourceThumbnailMaxPixelSize as String : w as NSNumber 
    ] as CFDictionary 

詳細:https://bugs.swift.org/browse/SR-2388

関連する問題