我有一个带有 calloutAccessoryControl 的 MKAnnotation。按下时,我显示一个 UIView:
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
NSDate *start = [NSDate date];
DLog(@"fired");
DLog(@"thread: %@", [NSThread currentThread]);
EntityPoint *entityPoint = (EntityPoint *)view.annotation;
EntityFormView *entityFormView = entityPoint.entityFormView;
DLog(@"addind subview: %f", [[NSDate date] timeIntervalSinceDate:start]);
[self.view addSubview:entityFormView.screenView];
DLog(@"addind constraints: %f", [[NSDate date] timeIntervalSinceDate:start]);
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[screenView]|" options:0 metrics:nil views:@{@"screenView": entityFormView.screenView}]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[screenView]|" options:0 metrics:nil views:@{@"screenView": entityFormView.screenView}]];
DLog(@"finished , doing animation: %f", [[NSDate date] timeIntervalSinceDate:start]);
[UIView animateWithDuration:.1
animations:^{
entityFormView.screenView.alpha = 1;
}
completion:^(BOOL finished) {
DLog(@"completely finished: %f", [[NSDate date] timeIntervalSinceDate:start]);
}];
}
我第一次运行此代码时,它发生在 ~.2 秒内。我关闭它然后重新打开它,这将需要大约 1.2 秒:
DEBUG | -[MapViewController mapView:annotationView:calloutAccessoryControlTapped:] | fired
DEBUG | -[MapViewController mapView:annotationView:calloutAccessoryControlTapped:] | thread: <NSThread: 0x1d548bc0>{name = (null), num = 1}
DEBUG | -[MapViewController mapView:annotationView:calloutAccessoryControlTapped:] | addind subview: 0.005463
DEBUG | -[MapViewController mapView:annotationView:calloutAccessoryControlTapped:] | addind constraints: 0.047544
DEBUG | -[MapViewController mapView:annotationView:calloutAccessoryControlTapped:] | finished , doing animation: 0.049323
DEBUG | __74-[MapViewController mapView:annotationView:calloutAccessoryControlTapped:]_block_invoke1001 | completely finished: 0.199709
DEBUG | -[MapViewController mapView:annotationView:calloutAccessoryControlTapped:] | fired
DEBUG | -[MapViewController mapView:annotationView:calloutAccessoryControlTapped:] | thread: <NSThread: 0x1d548bc0>{name = (null), num = 1}
DEBUG | -[MapViewController mapView:annotationView:calloutAccessoryControlTapped:] | addind subview: 0.006285
DEBUG | -[MapViewController mapView:annotationView:calloutAccessoryControlTapped:] | addind constraints: 1.069605
DEBUG | -[MapViewController mapView:annotationView:calloutAccessoryControlTapped:] | finished , doing animation: 1.082836
DEBUG | __74-[MapViewController mapView:annotationView:calloutAccessoryControlTapped:]_block_invoke1001 | completely finished: 1.194132
当我删除 UIView 时:
-(void)removeForm {
[UIView animateWithDuration:.1
animations:^{
self.screenView.alpha = 0;
}
completion:^(BOOL finished) {
[self.screenView removeFromSuperview];
}];
}
为什么第一次花了这么长时间才添加子视图?/困惑