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]);
                 }];

}

このコードを初めて実行すると、約 0.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、アルファがまだ 0 である間にオフセットにアニメートしていたということです。オフセットにアニメートすると、アルファが 1 にアニメートされます。

于 2013-06-24T14:46:41.417 に答える