我将我的项目更新为Swift 3,我在以下pod中遇到了问题:https://github.com/Ramotion/expanding-collection它不再有效:(
问题如下,我将解释每个问题:
1-"操作员不应再与身体一起宣布;改为使用优先组"课程中以下一行的黄色警告"约束助手":
infix operator >>>- { associativity left precedence 150}
如何在Swift 3中写这个?
2 - "'>>> - '产生' NSLayoutConstraint',而不是预期的上下文结果类型' Void' (又名'()')"类中的以下行出现红色错误" Constraints Helper":
func addScaleToFillConstratinsOnView(_ view: UIView) {
[NSLayoutAttribute.left, .right, .top, .bottom].forEach { attribute in
(self, view) >>>- { $0.attribute = attribute }
}
}
如何解决此问题?
3 - "运营商的结果'>>> - '未使用" AnimatingBarButton类中以下行的黄色警告:
fileprivate func configureImageView(_ imageView: UIImageView, imageName: String) {
guard let customView = customView else { return }
imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.image = UIImage(named: imageName)
imageView.contentMode = .scaleAspectFit
// imageView.backgroundColor = .greenColor()
// imageView.layer.anchorPoint = CGPoint(x: 0.5, y: 0.5)
customView.addSubview(imageView)
//Result of operator '>>>-' is unused - HERE 1
[(NSLayoutAttribute.centerX, 12), (.centerY, -1)].forEach { info in
(customView, imageView) >>>- {
$0.attribute = info.0
$0.constant = CGFloat(info.1)
}
}
//Result of operator '>>>-' is unused - HERE 2
[NSLayoutAttribute.height, .width].forEach { attribute in
imageView >>>- {
$0.attribute = attribute
$0.constant = 20
}
}
}
此外,我在BasePageCollectionCell的这段代码中遇到了同样的错误:
fileprivate func createShadowViewOnView(_ view: UIView?) -> UIView? {
guard let view = view else {return nil}
let shadow = Init(UIView(frame: .zero)) {
$0.backgroundColor = .clear
$0.translatesAutoresizingMaskIntoConstraints = false
$0.layer.masksToBounds = false;
$0.layer.shadowColor = UIColor.black.cgColor
$0.layer.shadowRadius = 10
$0.layer.shadowOpacity = 0.3
$0.layer.shadowOffset = CGSize(width: 0, height:0)
}
contentView.insertSubview(shadow, belowSubview: view)
for info: (attribute: NSLayoutAttribute, scale: CGFloat) in [(NSLayoutAttribute.width, 0.8), (NSLayoutAttribute.height, 0.9)] {
if let frontViewConstraint = view.getConstraint(info.attribute) {
//Result of operator '>>>-' is unused
shadow >>>- {
$0.attribute = info.attribute
$0.constant = frontViewConstraint.constant * info.scale
}
}
}
for info: (attribute: NSLayoutAttribute, offset: CGFloat) in [(NSLayoutAttribute.centerX, 0), (NSLayoutAttribute.centerY, 30)] {
//Result of operator '>>>-' is unused
(contentView, shadow, view) >>>- {
$0.attribute = info.attribute
$0.constant = info.offset
}
}
// size shadow
let width = shadow.getConstraint(.width)?.constant
let height = shadow.getConstraint(.height)?.constant
shadow.layer.shadowPath = UIBezierPath(roundedRect: CGRect(x: 0, y: 0, width: width!, height: height!), cornerRadius: 0).cgPath
return shadow
}
MARK:- PageCollectionView
//Result of operator '>>>-' is unused
collectionView >>>- {
$0.attribute = .height
$0.constant = height
}
如何解决此问题?
我知道这很长,并且作者需要解决这些问题,但作者没有回复或让我们知道有关更新的ETA。我正准备完成我的应用程序,然后更新到Swift 3,如果你能引导我完成这一点,我将非常感激。 PS:很多人在这个库中遇到类似的问题,我将在该库的支持页面中分享您的解决方案。
最佳, AA