In my viewDidLoad method, I have code to create MKMapView, some limitations and UIToolbar:
I have 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];
I create 2 constraints to make them fullscreen:
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];
It works great. But when I try to add something to the map view:
UIToolbar *topBar = [[UIToolbar alloc ]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)]; [topBar setTranslatesAutoresizingMaskIntoConstraints:NO]; topBar.barStyle = UIBarStyleBlackTranslucent; [mapView addSubview:topBar];
it gives an error:
*** 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 implementation of -layoutSubviews needs to call super.'
From my point of view, since I am adding a new view to the map view, is it necessary to recalculate all restrictions in it to display the map? Basically, the drawRect method for constraints.
How can i fix this?
source share