Files
MapLibreParticleLab/ios/app/MBXCustomCalloutView.m
Minh Nguyễn 9350d3f78c [ios] Converted iOS SDK into dynamic framework
make iproj now produces a target that pulls together static libraries like core and platform-ios into a real dynamic framework. iosapp is pretty much just a regular iOS application that links Mapbox.framework (except for the inclusion of default_styles.hpp). iosapp runs fine in the Simulator and on a device, and the same is true for any application linking against Mapbox.framework.

The ipackage target produces both a Bitcode-disabled static framework and a Bitcode-enabled dynamic framework, eliminating the need for a separate framework.sh. It disables code signing, since that happens on copy when the framework is embedded inside the application bundle. It also merges the device and simulator builds into a single fat framework.

Also bumped itest minimum deployment target to iOS 8.0, the first version that supports linking frameworks.

Fixes #828.
2016-01-22 14:45:56 -08:00

96 lines
3.0 KiB
Objective-C

#import "MBXCustomCalloutView.h"
static CGFloat const tipHeight = 10.0;
static CGFloat const tipWidth = 10.0;
@interface MBXCustomCalloutView ()
@property (strong, nonatomic) UILabel *mainLabel;
@end
@implementation MBXCustomCalloutView {
id <MGLAnnotation> _representedObject;
UIView *_leftAccessoryView;
UIView *_rightAccessoryView;
__weak id <MGLCalloutViewDelegate> _delegate;
}
@synthesize representedObject = _representedObject;
@synthesize leftAccessoryView = _leftAccessoryView;
@synthesize rightAccessoryView = _rightAccessoryView;
@synthesize delegate = _delegate;
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
self.backgroundColor = [UIColor clearColor];
_mainLabel = [[UILabel alloc] initWithFrame: CGRectZero];
_mainLabel.backgroundColor = [UIColor clearColor];
[self addSubview: _mainLabel];
}
return self;
}
#pragma mark - API
- (void)presentCalloutFromRect:(CGRect)rect inView:(UIView *)view constrainedToView:(UIView *)constrainedView animated:(BOOL)animated
{
[view addSubview:self];
// prepare title label
if ([self.representedObject respondsToSelector:@selector(title)])
{
self.mainLabel.text = self.representedObject.title;
[self.mainLabel sizeToFit];
}
// prepare our frame
CGFloat frameWidth = self.mainLabel.bounds.size.width;
CGFloat frameHeight = self.mainLabel.bounds.size.height * 2.0;
CGFloat frameOriginX = rect.origin.x + (rect.size.width/2.0) - (frameWidth/2.0);
CGFloat frameOriginY = rect.origin.y - frameHeight;
self.frame = CGRectMake(frameOriginX, frameOriginY,
frameWidth, frameHeight);
}
- (void)dismissCalloutAnimated:(BOOL)animated
{
if (self.superview)
[self removeFromSuperview];
}
#pragma mark - internals
- (void)drawRect:(CGRect)rect
{
UIColor *fillColor = [UIColor colorWithWhite:0.7 alpha:1.0];
CGFloat tipLeft = rect.origin.x + (rect.size.width / 2.0) - (tipWidth / 2.0);
CGPoint tipBottom = CGPointMake(rect.origin.x + (rect.size.width / 2.0), rect.origin.y +rect.size.height);
CGFloat heightWithoutTip = rect.size.height - tipHeight;
// draw the white background with tip
CGContextRef ctxt = UIGraphicsGetCurrentContext();
CGMutablePathRef tipPath = CGPathCreateMutable();
CGPathMoveToPoint(tipPath, NULL, 0, 0);
CGPathAddLineToPoint(tipPath, NULL, 0, heightWithoutTip);
CGPathAddLineToPoint(tipPath, NULL, tipLeft, heightWithoutTip);
CGPathAddLineToPoint(tipPath, NULL, tipBottom.x, tipBottom.y);
CGPathAddLineToPoint(tipPath, NULL, tipLeft + tipWidth, heightWithoutTip);
CGPathAddLineToPoint(tipPath, NULL, CGRectGetWidth(rect), heightWithoutTip);
CGPathAddLineToPoint(tipPath, NULL, CGRectGetWidth(rect), 0);
CGPathCloseSubpath(tipPath);
[fillColor setFill];
CGContextAddPath(ctxt, tipPath);
CGContextFillPath(ctxt);
CGPathRelease(tipPath);
}
@end