我必須面對的iOS 8 我有自定義視圖(UIView的子類),它包含的MKMapView在它的MKMapView的一些奇怪的行爲空白。的MKMapView顯示在批註選擇iOS8上
NMView -> MKMapView
NMView代碼
#import "NMView.h"
@implementation NMView
@synthesize mapView;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
frame=self.bounds;
self.translatesAutoresizingMaskIntoConstraints=NO;
mapView=[[MKMapView alloc]initWithFrame:frame];
mapView.showsUserLocation=YES;
[mapView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
[self setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
mapView.delegate=self;
[self addSubview:mapView];
self.backgroundColor=[UIColor grayColor];
}
return self;
}
-(void)addCustomAnnotaion:(id<MKAnnotation>)annot{
MKCoordinateRegion region=MKCoordinateRegionMake(annot.coordinate, MKCoordinateSpanMake(10.0f, 10.0f));
[mapView setRegion:region];
[mapView addAnnotation:annot];
// [mapView selectAnnotation:annot animated:YES];
}
- (MKAnnotationView *)mapView:(MKMapView *)mapViews viewForAnnotation:(id <MKAnnotation>)annotation
{
if ([annotation isKindOfClass:[MKUserLocation class]]){
return nil;
}
static NSString * const identifier = @"MyCustomAnnotation";
MKAnnotationView* annotationView = (MKAnnotationView*)[mapViews dequeueReusableAnnotationViewWithIdentifier:identifier];
if (annotationView){
annotationView.annotation = annotation;
}
else{
annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
annotationView.canShowCallout = YES;
UIView *rightView=[[UIView alloc]initWithFrame:CGRectMake(5, 0, 80,50)];
rightView.backgroundColor=[UIColor clearColor];
UIButton* edit = [UIButton buttonWithType:UIButtonTypeCustom];
[edit setImage:[UIImage imageNamed:@"editPOI"] forState:UIControlStateNormal];
[edit addTarget:self action:@selector(editPoi:) forControlEvents:UIControlEventTouchUpInside];
edit.backgroundColor=[UIColor clearColor];
edit.frame=CGRectMake(15, 5, 30,30);
UIButton* delButton = [UIButton buttonWithType:UIButtonTypeCustom];
[delButton setImage:[UIImage imageNamed:@"deletePOI"] forState:UIControlStateNormal];
[delButton addTarget:self action:@selector(deletePoi:) forControlEvents:UIControlEventTouchUpInside];
delButton.backgroundColor=[UIColor clearColor];
delButton.frame=CGRectMake(55, 5, 30,30);
[rightView addSubview:delButton];
[rightView addSubview:edit];
UIImageView *imgviewIcon=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
[imgviewIcon setImage:[UIImage imageNamed:@"pin.png"]];
[annotationView setImage:[UIImage imageNamed:@"pin.png"]];
[annotationView layoutIfNeeded];
annotationView.leftCalloutAccessoryView=imgviewIcon;
annotationView.rightCalloutAccessoryView=rightView;
}
return annotationView;
}
-(IBAction)editPoi:(id)sender{
//edit
}
-(IBAction)deletePoi:(id)sender{
//delete
}
我加入NMView到我的視圖控制器
NMView *nv=[[NMView alloc]initWithFrame:CGRectMake(5, 5, 300, 400)];
[self.view addSubview:nv];
現在我加入註解使用NMView的定製方法MapView類,
MKPointAnnotation *point=[[MKPointAnnotation alloc]init];
point.coordinate=pinCoordinate;
[email protected]"test";
[nv addCustomAnnotaion:point];
我在iOS7在其優良的工作進行了測試:
但iOS8上上標註的選擇全NMView一片空白。
是它的iOS 8的錯誤還是我做錯了什麼? 請幫助..
編輯
如果我選擇註釋編程然後也同樣的問題發生在iOS的8
[mapView selectAnnotation:annot animated:YES];
某些別有用心的人的基礎面這一問題?
iOS8上的空白屏幕。 :
我在上傳項目如下網址: https://drive.google.com/file/d/0BxkVP7smm8Z6SnM1UjBxcjc5aDg/view?usp=sharing
請檢查它讓我知道..
無關你的問題,但如果你沒有設置你的註釋視圖的'centerOffset'時,縮小時會顯示錯誤的點,在您的情況下是英文頻道。 – Desdenova 2014-10-03 08:45:24
@Desdenova:謝謝你的回覆,但現在這不是問題,主要問題是mkmapview在註釋選擇上變爲空白。 – user3057005 2014-10-03 09:40:53
請參閱我的anser下http://stackoverflow.com/questions/14707080/after-json-parsing-viewforannotation-shows-only-one-single-annotation-on-mkmapv/32965056#32965056希望也有助於某人。 – blackjacx 2015-10-06 08:26:01