Iphone 双击“缩放”时注释视图消失的问题
我在iPhone上的MapKit中遇到注释视图问题。我设法在地图上绘制自定义注释视图-没有问题。我甚至在拖动或缩放后重新绘制了它们。但是,在某些情况下重绘不起作用:例如双击缩放 我附加了一些代码,在地图上的特定位置画了几个矩形,当我用两个手指的手势缩放时,一切正常(即,矩形被重新绘制)。但是,当我双击时,矩形消失了。更奇怪的是,所有的方法都是按照它们应该被调用的顺序被调用的,最后,甚至drawRect也被调用了——但矩形并没有被绘制出来 下面是代码,请自己尝试-双手指缩放可以工作,但双击缩放不行: PlaygroundViewController.hIphone 双击“缩放”时注释视图消失的问题,iphone,annotations,mapkit,quartz-graphics,Iphone,Annotations,Mapkit,Quartz Graphics,我在iPhone上的MapKit中遇到注释视图问题。我设法在地图上绘制自定义注释视图-没有问题。我甚至在拖动或缩放后重新绘制了它们。但是,在某些情况下重绘不起作用:例如双击缩放 我附加了一些代码,在地图上的特定位置画了几个矩形,当我用两个手指的手势缩放时,一切正常(即,矩形被重新绘制)。但是,当我双击时,矩形消失了。更奇怪的是,所有的方法都是按照它们应该被调用的顺序被调用的,最后,甚至drawRect也被调用了——但矩形并没有被绘制出来 下面是代码,请自己尝试-双手指缩放可以工作,但双击缩放不行
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@interface PlaygroundViewController : UIViewController <MKMapViewDelegate>{
MKMapView *mapView_;
NSMutableDictionary* myViews_;
}
@end
TerritoryView.h
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
@interface TerritoryView : MKAnnotationView {
}
- (id)initWithAnnotation:(id <MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier;
- (void)initRedraw;
@end
#导入
#进口
@接口TerritoryView:MKAnnotationView{
}
-(id)initWithAnnotation:(id)注释重用标识符:(NSString*)重用标识符;
-(无效)重新绘制;
@结束
TerritoryView.m
#import "TerritoryView.h"
@implementation TerritoryView
- (id)initWithAnnotation:(id <MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier {
if ([super initWithAnnotation:annotation reuseIdentifier:@"Territory"]) {
self.initRedraw;
}
return self;
}
- (void)initRedraw {
self.frame = CGRectMake(0,0,40,40);
[self setNeedsDisplay];
}
- (void)drawRect:(CGRect)rect {
NSLog(@"in draw rect");
}
@end
#导入“TerritoryView.h”
@实现地域视图
-(id)initWithAnnotation:(id)注释重用标识符:(NSString*)重用标识符{
if([super-initWithAnnotation:annotation-reuseIdentifier:@“Territory”]){
self.initRedraw;
}
回归自我;
}
-(无效)重新绘制{
self.frame=CGRectMake(0,0,40,40);
[自我设置需要显示];
}
-(void)drawRect:(CGRect)rect{
NSLog(@“in draw rect”);
}
@结束
感谢您的帮助。这是压缩后的项目:请记住,帧的原点位于其父帧的坐标系中,因此将其设置为零可能会使其脱离屏幕。我怀疑它之所以能工作,是因为它在大多数情况下都是在你背后重置的,但在那些失败的情况下却不是这样 替换: self.frame=CGRectMake(0,0,40,40) 与:
self.frame=CGRectMake(self.frame.origin.x,self.frame.origin.y,40,40) 请发布压缩项目。好的,在文章末尾添加了压缩项目的链接。
#import "Territory.h"
@implementation Territory
@synthesize latitude_;
@synthesize longitude_;
@synthesize territoryID_;
- (CLLocationCoordinate2D)coordinate {
CLLocationCoordinate2D coord_ = {self.latitude_, self.longitude_};
return coord_;
}
-(id) init {
if (self = [super init]) {
self.territoryID_ = [NSString stringWithFormat:@"%p", self];
}
return self;
}
@end
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
@interface TerritoryView : MKAnnotationView {
}
- (id)initWithAnnotation:(id <MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier;
- (void)initRedraw;
@end
#import "TerritoryView.h"
@implementation TerritoryView
- (id)initWithAnnotation:(id <MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier {
if ([super initWithAnnotation:annotation reuseIdentifier:@"Territory"]) {
self.initRedraw;
}
return self;
}
- (void)initRedraw {
self.frame = CGRectMake(0,0,40,40);
[self setNeedsDisplay];
}
- (void)drawRect:(CGRect)rect {
NSLog(@"in draw rect");
}
@end