Mapkit自定义注释快照器UIView

时间:2019-06-26 20:06:56

标签: swift uiview mapkit mkmapsnapshotter

without code to fix it screenshot of the desired but get warnings我创建了一个简单的.xib并将其作为UIView的子类加载。 .xib的内容太大,无法容纳在快照中。我可以更改UIView /快照视图的框架,并且可以,但是我在控制台中收到了大量调试消息。

像.xib一样,常量的宽度和高度最初设置为300和200,但是我没有得到想要的效果。只有将其设置为3和2时,我才能看到想要的内容。

func configureCallOutView(mkAnnotation: MKAnnotationView) {
        let width = 3
        let height = 2

        let snapshotView = UIView()
        let views = ["snapshotView": snapshotView]
        snapshotView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:[snapshotView(300)]", options: [], metrics: nil, views: views))
        snapshotView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:[snapshotView(200)]", options: [], metrics: nil, views: views))

        let options = MKMapSnapshotter.Options()
        options.size = CGSize(width: width, height: height)
        options.mapType = .satelliteFlyover
        options.camera = MKMapCamera(lookingAtCenter: mkAnnotation.annotation!.coordinate, fromDistance: 250, pitch: 65, heading: 0)

        let snapshotter = MKMapSnapshotter(options: options)
        snapshotter.start { snapshot, error in
            if snapshot != nil {
                if let imageView = UINib.init(nibName: "TruckAnnotationView", bundle: nil).instantiate(withOwner: self, options: nil)[0] as? TruckAnnotationView {
                    imageView.frame = CGRect(x: 0, y: 0, width: width, height: height)
                    imageView.companyLogo.image = UIImage(named: "truck")
                    imageView.companyName.text = "Test Name"
                    imageView.layoutIfNeeded()

                    snapshotView.addSubview(imageView)

                }
            }
        }

        mkAnnotation.detailCalloutAccessoryView = snapshotView

    }
Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x6000012d32f0 UIImageView:0x7fd469f47ac0.centerY == UIView:0x7fd469f47280.centerY   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
2019-06-26 15:58:05.687470-0400 Truck It[96190:847804] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x6000012d2ee0 V:[UILabel:0x7fd469f47460'Test Name']-(10)-|   (active, names: '|':UIView:0x7fd469f47280 )>",
    "<NSLayoutConstraint:0x6000012d0000 V:|-(10)-[UILabel:0x7fd469f47460'Test Name']   (active, names: '|':UIView:0x7fd469f47280 )>",
    "<NSLayoutConstraint:0x6000012d26c0 V:|-(0)-[UIView:0x7fd469f47280]   (active, names: '|':Truck_It.TruckAnnotationView:0x7fd469f46d60 )>",
    "<NSLayoutConstraint:0x6000012d3b60 V:[UIView:0x7fd469f47cf0]-(0)-|   (active, names: '|':Truck_It.TruckAnnotationView:0x7fd469f46d60 )>",
    "<NSLayoutConstraint:0x6000012d1680 V:[UIView:0x7fd469f47280]-(0)-[UIView:0x7fd469f47cf0]   (active)>",
    "<NSLayoutConstraint:0x6000011053b0 '_UITemporaryLayoutHeight' Truck_It.TruckAnnotationView:0x7fd469f46d60.height == 2   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x6000012d2ee0 V:[UILabel:0x7fd469f47460'Test Name']-(10)-|   (active, names: '|':UIView:0x7fd469f47280 )>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.

0 个答案:

没有答案