我认为iOS 7 MKMapSnapshotter是一种拍摄快照的简单方法MKMapView,其好处是可以在不将地图加载到视图中的情况下完成.即使添加引脚和覆盖图似乎更多的工作(因为需要核心图形).WWDC视频提供了一个非常好的例子来创建一个MKMapSnapshotter添加MKAnnotationView.
然而,对于没有很多核心图形经验的人来说,如何创建一个MKMapSnapshotter来自的人并不是很明显MKPolylineRenderer.
我试过这样做,但路径不准确.它准确地绘制了大约10%的线,但随后直接绘制了剩下的路径.
这是我的代码:
MKMapSnapshotter *snapshotter = [[MKMapSnapshotter alloc] initWithOptions:snapshotOptions];
[snapshotter startWithQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
completionHandler:^(MKMapSnapshot *snapshot, NSError *error)
{
if (error == nil)
{
UIImage *mapSnapshot = [snapshot image];
UIGraphicsBeginImageContextWithOptions(mapSnapshot.size,
YES,
mapSnapshot.scale);
[mapSnapshot drawAtPoint:CGPointMake(0.0f, 0.0f)];
CGContextRef context = UIGraphicsGetCurrentContext();
//Draw the points from the MKPolylineRenderer in core graphics for mapsnapshotter...
MKPolylineRenderer *overlay = (MKPolylineRenderer *)[self.mapView rendererForOverlay:[_mapView.overlays lastObject]];
if (overlay.path)
{
CGFloat zoomScale = 3.0;
[overlay applyStrokePropertiesToContext:context
atZoomScale:zoomScale];
CGContextAddPath(context, …Run Code Online (Sandbox Code Playgroud) 你是如何为David Maymudes的答案中提供的应用程序"创建促销代码"(问题链接下方)?它有iOS UI吗?
在过去的一年里,我第一次与其他人一起开展了一些Objective-C项目.
偶尔(并且越来越多)我看到其他人重写getter/accessor方法,并且在这个方法中包含实现代码!对我来说,这是一个疯狂的城镇,因为这是拥有一个二传手的全部意义......这也意味着设置在setter中的属性将在getter中被覆盖,因此毫无意义.
这些人表现得很糟糕,还是我错过了什么?是否需要覆盖合成属性的getter方法?
例:
@synthesize width;
- (CGFloat)width {
NSNumber *userWidth = [[NSUserDefaults standardUserDefaults] objectForKey:@"USER_WIDTH"];
if (userWidth != nil)
{
width = [NSNumber floatValue];
}
//Shouldn't the above lines be done in the SETTER? I have SET the property!
//Why would I ever need to write anything BUT the below line??
return width;
}
- (void)setWidth:(CGFloat)newWidth {
//THIS is where you do the the setting!
width = newWidth;
}
Run Code Online (Sandbox Code Playgroud)
更新:
好宽度是一个坏例子.太多的人都陷入了"变量是什么"和"不包括get-objective-c访问器"的语义.所以我更新了上面的例子来忽略不相关的语义,并专注于这个概念.这个概念是...当你想要覆盖GETTER时没有任何例子(不是setter,只有getter.我多次覆盖setter,这个问题是关于getter的)?
返回另一个属性,如图层(如下所述)是一个真实的例子.但更具体地说,是否需要在GETTER中设置属性?这是我所看到的一些奇怪之处,所以我更新了上面的getter来从NSUserDefaults中提取一个值以帮助我的观点......
我在我的故事板中设置了这个UIViewController,包含了我需要的所有插座,视图和约束.完善.让我们调用这个WatchStateController,它将作为一个抽象的父类.
然后我有了WatchStateController的这个子类,叫做WatchStateTimeController,它将具有我需要的特定应用程序状态的功能.
因为我试图在UIStoryboard中使用1视图控制器,我在将WatchStateTimeController实例化为类型WatchStateTimeController时遇到了一些问题 - 它实例化为WatchStateController.
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
WatchStateTimeController *timeController = (WatchStateTimeController *)[mainStoryboard instantiateViewControllerWithIdentifier:@"WatchStateController"];
Run Code Online (Sandbox Code Playgroud)
这是因为故事板的Identity Inspector中的"Class"字段设置为"WatchStateController".所以问题是,我如何仅在运行时更改Identity Inspector中设置的类名?

注意:忽略我为什么要这样做并专注于如何做到这一点.如果你真的必须知道原因,你可以阅读战略设计模式.
好吧,我必须修复其他人的代码,基本上在892行有一个ELSE/IF语句,但我找不到原始的IF语句!不一致的嵌套使得这非常困难.
我拖着代码,看看我是否可以找到原件,但我不能.除了用鼠标滚动之外,有没有人有什么想法可以搜索原始的IF语句?
顺便说一句,我正在使用Eclipse.谢谢 :)
ios ×3
iphone ×2
eclipse ×1
ios7 ×1
mkmapview ×1
mkpolyline ×1
objective-c ×1
properties ×1
storyboard ×1
xcode ×1