Рендеринг MKMarkerAnnotationView проблема - вырезать сверху - PullRequest
1 голос
/ 02 апреля 2019

Я пытаюсь получить изображение MKMarkerAnnotationView. Может заставить это почти работать, но вершина сокращена. Пробовал раскладывать подпредставления, пока ничего не помогло.

enter image description here

@interface FakeStation : NSObject<MKAnnotation>
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;
@property (nonatomic) CLLocationCoordinate2D coordinate;
@end
@implementation FakeStation
@end


- (UIImage *)custiomAnnotationImage
{
    FakeStation *fakeStation = [[FakeStation alloc] init];;
    fakeStation.title  = @"title"
    fakeStation.subtitle  = @"subtitle"
    fakeStation.coordinate = CLLocationCoordinate2DMake(0, 0);
    MKMarkerAnnotationView *view = [[MKMarkerAnnotationView alloc] initWithAnnotation:fakeStation reuseIdentifier:@"testIdentifier"];
    view.glyphText = @"0/5";
    view.markerTintColor = [UIColor blackColor];
    [view prepareForDisplay];
    CALayer *layer = [view layer];
    UIGraphicsBeginImageContextWithOptions(layer.frame.size, NO, 0);

    [layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext();    UIGraphicsEndImageContext();
    return outputImage;
}

Выход LLDB:

(lldb) po layer
<CALayer:0x608000631820; position = CGPoint (14 14); bounds = CGRect (0 0; 28 28); delegate = <MKMarkerAnnotationView: 0x7fdb2f3e7600; frame = (0 0; 28 28); layer = <CALayer: 0x608000631820>>; sublayers = (<CALayer: 0x608000631840>, <CAShapeLayer: 0x608000631b00>); opaque = YES; allowsGroupOpacity = YES; >

(lldb) po 0x608000631840
<CALayer:0x608000631840; position = CGPoint (40.5 37.5); bounds = CGRect (0 0; 81 75); delegate = <UIImageView: 0x7fdb3af79580; frame = (20.25 5.5; 40.5 37.5); transform = [0.5, 0, 0, 0.5, 0, 0]; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x608000631840>>; contents = <CGImage 0x6040001d8150>
    <<CGColorSpace 0x6000000a3b40> (kCGColorSpaceICCBased; kCGColorSpaceModelMonochrome; Generic Gray Gamma 2.2 Profile)>
        width = 243, height = 225, bpc = 8, bpp = 16, row bytes = 486 
        kCGImageAlphaPremultipliedLast | 0 (default byte order) 
        is mask? No, has mask? No, has matte? No, should interpolate? Yes; allowsGroupOpacity = YES; anchorPoint = CGPoint (0.5 0.853333); transform = CATransform3D (0.5 0 0 0; 0 0.5 0 0; 0 0 1 0; 0 0 0 1); rasterizationScale = 3; contentsScale = 3; contentsMultiplyColor = (null)>

(lldb) po 0x608000631b00
<CAShapeLayer:0x608000631b00; position = CGPoint (14 16.5); bounds = CGRect (0 0; 28 33); delegate = <_MKBezierPathView: 0x7fdb3af797b0; frame = (0 -16.5; 28 33); layer = <CAShapeLayer: 0x608000631b00>>; sublayers = (<CALayer: 0x608000631ba0>, <_UILabelLayer: 0x60800089b490>); opaque = YES; allowsGroupOpacity = YES; lineWidth = 0; fillColor = <CGColor 0x6080004aa8c0> [<CGColorSpace 0x6040000a3a20> (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; sRGB IEC61966-2.1; extended range)] ( 0.996078 0.933333 0.207843 1 ); anchorPoint = CGPoint (0.5 1); contentsCenter = CGRect (0 0; 1 0.848485); path = <CGPath 0x608000631b80>>
...