ios - 渲染 MKMarkerAnnotationView 问题 - 从顶部截取
问题描述
我正在尝试获取 MKMarkerAnnotationView 的图像。几乎可以让它工作,但顶部被切掉了。试图布局子视图,到目前为止没有任何帮助。
@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>>
解决方案
推荐阅读
- sql-server - 从 SQL Server 2008 升级到 2016 使查询变慢
- bosch-iot-suite - 提取的jar文件找不到主类
- mysql - 如何在 MYSQL 中将 ISO8601 时间转换为日期时间
- python - 在 python 3 中创建一个序列
- swift - 电话号码的自定义 Swift 格式化程序
- python - 更改活动窗口
- sql - Postgres 数据类型声明和键入,双冒号和非冒号有什么区别
- azure - Azure 默认变量未在表达式中求值
- .net - 媒体类型不支持 415 从 Angular 7 SPA 到 .NET,而请求在 Postman 中工作
- javascript - 提交 Google 表单时,如果我使用多个函数调用,函数将不起作用