我有以下符合 UIView 的类:
import UIKit
class LocationInformationCalloutView: UIView {
:
:
然后我有第二堂课,如下所示:
class LocationInformationAnnotationView: MKAnnotationView {
weak var customCalloutView : LocationInformationCalloutView?
}
}
:
:
所以你可以看到我有一个名为的变量customAnnotationView,它的类型LocationInformationCalloutView是类型UIView
该loadLocationInformationCalloutView()函数看起来像这样(只是一个返回 UIView 的函数):
func loadLocationInformationCalloutView() -> UIView? {
let view = UIView(frame: CGRect(x: 0, y: 0, width: 240, height: 280))
return view
}
但是在调用这行代码时:
self.customCalloutView = newCustomCalloutView
在这段代码中:
override func setSelected(_ selected: Bool, animated: Bool) {
if selected {
self.customCalloutView?.removeFromSuperview()
if let newCustomCalloutView = loadLocationInformationCalloutView() {
newCustomCalloutView.frame.origin.x -= newCustomCalloutView.frame.width / 2.0 - (self.frame.width / 2.0)
newCustomCalloutView.frame.origin.y -= newCustomCalloutView.frame.height
self.addSubview(newCustomCalloutView)
self.customCalloutView = newCustomCalloutView
if animated {
self.customCalloutView!.alpha = 0.0
UIView.animate(withDuration: 1.8, animations: {
self.customCalloutView!.alpha = 1.0
})
我收到以下错误:
无法将“UIView”类型的值分配给“LocationInformationnCalloutView?”
有人可以对此有所了解并帮助我解决这个问题吗?非常感谢任何帮助,谢谢!