嘿伙计们,
如果我在标注视图中使用自动布局,我的应用程序就会在MKMapView 6下崩溃。使用iOS 7,这是很好的工作。
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {
CustomMapAnnotation *annotation = (CustomMapAnnotation *)view.annotation;
if([annotation isKindOfClass:[CustomMapAnnotation class]]) {
CustomMapCalloutView *calloutView = [CustomMapCalloutView new];
calloutView.translatesAutoresizingMaskIntoConstraints = NO;
calloutView.titleLabel.text = annotation.titleText;
calloutView.subTitleLabel.text = annotation.subTitleText;
calloutView.distanceTextLabel.text = annotation.distanceText;
[view addSubview:calloutView];
NSDictionary *viewsDictionary = @{@"callOutView": calloutView};
NSArray *hConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:[callOutView(150)]" options:0 metrics:nil views:viewsDictionary];
NSArray *vConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[callOutView(50)]" options:0 metrics:nil views:viewsDictionary];
NSLayoutConstraint *xConstraint = [NSLayoutConstraint constraintWithItem:calloutView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:view attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0.0];
NSLayoutConstraint *yConstraint = [NSLayoutConstraint constraintWithItem:calloutView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:view attribute:NSLayoutAttributeTop multiplier:1.0 constant:0.0];
[view addConstraint:xConstraint];
[view addConstraint:yConstraint];
[view addConstraints:hConstraints];
[view addConstraints:vConstraints];
}}控制台显示以下错误:
/SourceCache/UIKit_Sim/UIKit-2380.17/UIView.m:5776 2013-27 13:39:18.519 Layout烈士9825:907 *终止应用程序,原因是:“执行-layoutSubviews之后仍然需要自动布局。MKAnnotationView实现-layoutSubviews需要调用Super.”。
有人能告诉我问题出在哪里吗?CustomCalloutView也适用于自动布局,我不会在其中覆盖layoutSubviews。
发布于 2013-10-27 21:28:16
这个SO Answer指向了我正确的方向。我在MKAnnotationView上创建了一个类别,覆盖了layoutSubviews方法并调用了超级方法。
这也适用于iOS 7。
https://stackoverflow.com/questions/19618415
复制相似问题