本文介绍了重置标题/副标题后如何调整标注气泡的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个 MKAnnotation 名称 PushPin,它有一个标题和副标题.我希望能够在以后动态更改标题.我很接近所以我宁愿不必制作一个全新的 AnnotationView,但如果我必须这样做,我想这也没关系.我的问题是,一旦我更改了标题的文本,窗口就不会调整大小,并且根据标题最初的大小,某些文本可能会被截断.

I created an MKAnnotation name PushPin which has a title and subtitle. I want to be able to dynamically change the title at a later time. I'm close so I'd rather not have to make a whole new AnnotationView, but if I have to I guess that's ok too. My problem is that, once I change the text for the title, the window does not resize and some text might get cut off depending on how big the title originally was.

1) 是否可以触发一个事件来再次调整标注气泡窗口的大小?

1) Is there an event I can trigger to resize the callout bubble window again?

2) 另外,在我重置标题之前,我先检查以确保注释确实有标题,但是在我检查之后我在投射它时遇到了一些麻烦,有人可以帮我解决这个问题吗?我对objective-c 还是个新手,这个问题困扰了我一段时间.

2) Also, I check to make sure that the annotation actually has a title first before I go resetting the title, but I had some trouble casting it after I checked, can someone help me out with this? I'm still new to objective-c and this one messed with me for a while.

#import <Foundation/Foundation.h>
#import <MapKit/MKAnnotation.h>

@interface PushPin : NSObject <MKAnnotation> {
 CLLocationCoordinate2D _coordinate;
 NSString *_title;
 NSString *_subtitle;
 NSString *_ID;
}

@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
@property (nonatomic, retain) NSString *title;
@property (nonatomic, retain) NSString *subtitle;
@property (nonatomic, retain) NSString *ID;

- (id) initWithCoordinateAndInformation:(CLLocationCoordinate2D)coordinate title:(NSString *)title subtitle:(NSString *)subtitle;

@end
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
 NSLog(@"Annotation was TAPPED!");

 if ([view.annotation isKindOfClass:[PushPin class]]) {
  view.annotation.title = @"test";

          // warning here, that this might not be implemented...
          // but it is for this class type, how do I cast it to the correct type?
 }

}

推荐答案

仍有一些问题,但可能会越来越近.我试过这个,但仍然没有运气.我部分借鉴了 http 中的代码://digdog.tumblr.com/post/252784277/mapkit-annotation-drag-and-drop-with-callout-info

Still having some problems, but getting closer maybe. I tried this, but still no luck. I am partially drawing on the code from http://digdog.tumblr.com/post/252784277/mapkit-annotation-drag-and-drop-with-callout-info

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
    NSLog(@"Annotation was TAPPED!");

    if ([view.annotation isKindOfClass:[PushPin class]]) {
        ((PushPin *)view.annotation).title = @"test";
    }

    [self willChangeValueForKey:@"subtitle"]; // Workaround for SDK 3.0, otherwise callout info won't update.
    [self didChangeValueForKey:@"subtitle"]; // Workaround for SDK 3.0, otherwise callout info won't update.

    [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:@"MKAnnotationCalloutInfoDidChangeNotification" object:self]];
}

好消息是,我解决了我的选角问题,对于其他可能好奇的人来说.

Good news is that, I figured out my casting problem, for others who may be curious.

((PushPin *)view.annotation).title = @"test";

这篇关于重置标题/副标题后如何调整标注气泡的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 09:08