私の viewDidLoad メソッドには、MKMapView、いくつかの制約、および UIToolbar を作成するコードがあります。
私は MKMapView を持っています:
MKMapView *mapView = [[MKMapView alloc] init];
[mapView setTranslatesAutoresizingMaskIntoConstraints:NO];
mapView.userInteractionEnabled = TRUE;
mapView.showsUserLocation = TRUE;
mapView.mapType = MKMapTypeHybrid;
mapView.delegate = self;
[mapView setUserTrackingMode:MKUserTrackingModeFollow animated:YES];
[self.view addSubview:mapView];
全画面表示にするために 2 つの制約を作成します。
NSMutableArray *constraints = [NSMutableArray array];
[constraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[mapView]|"
options:0
metrics:nil
views:NSDictionaryOfVariableBindings(mapView)]];
[constraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"|[mapView]|"
options:0
metrics:nil
views:NSDictionaryOfVariableBindings(mapView)]];
[self.view addConstraints:constraints];
よく働く。しかし、マップビューに何かを追加しようとすると:
UIToolbar *topBar = [[UIToolbar alloc ]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];
[topBar setTranslatesAutoresizingMaskIntoConstraints:NO];
topBar.barStyle = UIBarStyleBlackTranslucent;
[mapView addSubview:topBar];
エラーがスローされます:
*** Assertion failure in -[MKMapView layoutSublayersOfLayer:], /SourceCache/UIKit_Sim/UIKit-2372/UIView.m:5776
2013-01-10 10:24:17.503 Landscout 2[2001:14003] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Auto Layout still required after executing -layoutSubviews. MKMapView's implementation of -layoutSubviews needs to call super.'
私の理解では、マップ ビューに新しいビューを追加しているため、マップ ビューはその中のすべての制約を再計算する必要がありますか? 基本的には、制約の drawRect メソッドです。
どうすればこれを修正できますか?