在 iOS6 中,我正在尝试为注释创建自定义标注,其中将包含图像、标题、描述等详细信息。我在这里看到了相关帖子,但不是我要找的。在我的应用程序中,当您选择注释时,您可以选择 4 个按钮。现在我正在尝试为第 4 个按钮创建选项,这是详细标注。
我已经创建了一个代表自定义标注的 UIView 类。
编辑:
在 Live2Enjoy7 的帮助下,我修改了我的代码如下。
BuildingViewController.m
- (void)MapMenu:(MapMenu *)menu didSelectButton:(NSInteger)index{
if (index == 3) {
image = [UIImage imageWithData: [NSData dataWithContentsOfURL:url]];
_buildingShowCallout = YES;
[parentView removeAnnotation:self];
[parentView addAnnotation:self];
}
}
如果用户按下按钮,此方法会创建新图像(使用 url 链接),设置 _buildingShowCallout = YES,最后删除并再次添加所选注释以使 viewForAnnotation 方法起作用。
在我的 MapViewController.m 中
- (MKAnnotationView *)mapView:(MKMapView *)_mapView viewForAnnotation:(id<MKAnnotation>)annotation{
if ([annotation isKindOfClass:[MKUserLocation class]]) {
return nil;
}
static NSString *identifier = @"MyAnnotation";
MKPinAnnotationView *annotationView = (MKPinAnnotationView *) [_mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
BuildingViewController* building = (BuildingViewController*) annotation;
// If a new annotation is created
if (annotationView == nil) {
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:building reuseIdentifier:identifier];
if (building.buildingShowCallout) {// Create the custom callout
BuildingCallOut* buildingCallout = [[BuildingCallOut alloc]initWithFrame:CGRectMake(0, 0, 200, 150)];
[buildingCallout showCallout:building];
[annotationView addSubview:buildingCallout];//add the new callout as subview of the selected annotation.
}
} else{
annotationView.annotation = annotation;
if (building.buildingShowCallout) {// Create the custom callout
BuildingCallOut* buildingCallout = [[BuildingCallOut alloc]initWithFrame:CGRectMake(0, 0, 200, 150)];
[buildingCallout showCallout:building];
[annotationView addSubview:buildingCallout];//add the new callout as subview of the selected annotation.
}
}
return annotationView;
}
一切正常,但现在我遇到了一个新问题。
截图 ![在此处输入图片描述][1]
如您所见.. 当我在底部调用新标注时,屏幕顶部的前一个标注仍然存在。努力寻找放置“消失”线的位置。 提前致谢
最佳答案
我猜您的 BuildingViewController 就是您的 MapViewController。
您想在 header 中将其声明为 MKMapViewDelegate。这将使您能够访问多种方法,这些方法允许您更改出现的注释甚至图钉的 View 。
首先,如果您还没有导入 MapKit/MapKit.h 和 UIKit/UIKit.h。
其次,声明您的 BuildingViewController 符合 MKMapViewDelegate 协议(protocol)(如上所述)。
第三,在 ViewDidLoad 中将您的 BuildingViewController 声明为 map View 的委托(delegate),例如:
self.mapView.delegate=self; //assuming that the you have a MKMapView named MapView in your layout
第四,实现这些协议(protocol)方法:
-(MKAnnotationView*)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation;
-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view;
第一种方法允许您设置左右呼出配件以及修改其他一些东西(这是您想要在 CGRectMakes 上做的地方)。
在第二种方法中,您决定在注释 View 中实际显示哪些数据。
搜索 MKMapViewDelegate 的文档 --> here
关于ios - 为注释创建自定义标注,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13546149/
出于纯粹的兴趣,我很好奇如何按顺序创建PI,而不是在过程结果之后生成数字,而是让数字在过程本身生成时显示。如果是这种情况,那么数字可以自行产生,我可以对以前看到的数字实现垃圾收集,从而创建一个无限系列。结果只是在Pi系列之后每秒生成一个数字。这是我通过互联网筛选的结果:这是流行的计算机友好算法,类机器算法:defarccot(x,unity)xpow=unity/xn=1sign=1sum=0loopdoterm=xpow/nbreakifterm==0sum+=sign*(xpow/n)xpow/=x*xn+=2sign=-signendsumenddefcalc_pi(digits
我正在尝试设置一个puppet节点,但rubygems似乎不正常。如果我通过它自己的二进制文件(/usr/lib/ruby/gems/1.8/gems/facter-1.5.8/bin/facter)在cli上运行facter,它工作正常,但如果我通过由rubygems(/usr/bin/facter)安装的二进制文件,它抛出:/usr/lib/ruby/1.8/facter/uptime.rb:11:undefinedmethod`get_uptime'forFacter::Util::Uptime:Module(NoMethodError)from/usr/lib/ruby
关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。
使用带有Rails插件的vim,您可以创建一个迁移文件,然后一次性打开该文件吗?textmate也可以这样吗? 最佳答案 你可以使用rails.vim然后做类似的事情::Rgeneratemigratonadd_foo_to_bar插件将打开迁移生成的文件,这正是您想要的。我不能代表textmate。 关于ruby-使用VimRails,您可以创建一个新的迁移文件并一次性打开它吗?,我们在StackOverflow上找到一个类似的问题: https://sta
我对最新版本的Rails有疑问。我创建了一个新应用程序(railsnewMyProject),但我没有脚本/生成,只有脚本/rails,当我输入ruby./script/railsgeneratepluginmy_plugin"Couldnotfindgeneratorplugin.".你知道如何生成插件模板吗?没有这个命令可以创建插件吗?PS:我正在使用Rails3.2.1和ruby1.8.7[universal-darwin11.0] 最佳答案 随着Rails3.2.0的发布,插件生成器已经被移除。查看变更日志here.现在
我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer
我想向我的Controller传递一个参数,它是一个简单的复选框,但我不知道如何在模型的form_for中引入它,这是我的观点:{:id=>'go_finance'}do|f|%>Transferirde:para:Entrada:"input",:placeholder=>"Quantofoiganho?"%>Saída:"output",:placeholder=>"Quantofoigasto?"%>Nota:我想做一个额外的复选框,但我该怎么做,模型中没有一个对象,而是一个要检查的对象,以便在Controller中创建一个ifelse,如果没有检查,请帮助我,非常感谢,谢谢
如何使用RSpec::Core::RakeTask初始化RSpecRake任务?require'rspec/core/rake_task'RSpec::Core::RakeTask.newdo|t|#whatdoIputinhere?endInitialize函数记录在http://rubydoc.info/github/rspec/rspec-core/RSpec/Core/RakeTask#initialize-instance_method没有很好的记录;它只是说:-(RakeTask)initialize(*args,&task_block)AnewinstanceofRake
我已经从我的命令行中获得了一切,所以我可以运行rubymyfile并且它可以正常工作。但是当我尝试从sublime中运行它时,我得到了undefinedmethod`require_relative'formain:Object有人知道我的sublime设置中缺少什么吗?我正在使用OSX并安装了rvm。 最佳答案 或者,您可以只使用“require”,它应该可以正常工作。我认为“require_relative”仅适用于ruby1.9+ 关于ruby-主要:Objectwhenrun
关闭。这个问题需要detailsorclarity.它目前不接受答案。想改进这个问题吗?通过editingthispost添加细节并澄清问题.关闭8年前。Improvethisquestion为什么SecureRandom.uuid创建一个唯一的字符串?SecureRandom.uuid#=>"35cb4e30-54e1-49f9-b5ce-4134799eb2c0"SecureRandom.uuid方法创建的字符串从不重复?