0

我有一个带有 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];
                     }];
}

为什么第一次花了这么长时间才添加子视图?/困惑

4

2 回答 2

0

我玩弄了它,在解决我遇到的另一个问题时,我也解决了这个问题。

表单视图是一个子类UIScrollView,要关闭视图,您需要向下滚动以单击保存按钮。这将导致contentOffset设置为 145。关闭后,我将其设置contentOffset为 0。这解决了我的显示缓慢问题。

我最好的猜测是,UIScrollView当 alpha 仍为 0 时,它正在对偏移进行动画处理。一旦动画到偏移,它会将 alpha 设置为 1。

于 2013-06-24T14:46:41.417 回答
0

看起来有点像第一次运行时,没有发生 alpha 动画,这很奇怪。您的完成completely finished日志应该在doing animation日志之后大约 1 秒加上时间戳。我想说从那里开始调查,因为这是事件序列中看起来不正确的第一件事。也许当它第一次运行时,UIView 的 alpha 已经是 1.0,所以它不会淡入?

于 2013-06-20T21:20:53.247 回答