我遇到了两个错误。当我在新的xcode 8 swift 3.0中打开我的项目时,我收到此错误我不知道如何纠正此错误。我已经解决了其他一些错误。但是在这一行中就上述错误触及了这一点。
func keyboardWillShow(_ notification: Notification) {
keyboardHasBeenShown = true
guard let userInfo = (notification as NSNotification).userInfo else {return}
guard let endKeyBoardFrame = (userInfo[UIKeyboardFrameEndUserInfoKey] as AnyObject).cgRectValue.minY else {return}
if tmpContentViewFrameOrigin == nil {
tmpContentViewFrameOrigin = self.contentView.frame.origin
}
if tmpCircleViewFrameOrigin == nil {
tmpCircleViewFrameOrigin = self.circleBG.frame.origin
}
var newContentViewFrameY = self.contentView.frame.maxY - endKeyBoardFrame
if newContentViewFrameY < 0 {
newContentViewFrameY = 0
}
let newBallViewFrameY = self.circleBG.frame.origin.y - newContentViewFrameY
self.contentView.frame.origin.y -= newContentViewFrameY
self.circleBG.frame.origin.y = newBallViewFrameY
}
在上面的方法中:
我的错误位于以下行:
guard let endKeyBoardFrame = (userInfo[UIKeyboardFrameEndUserInfoKey] as AnyObject).cgRectValue.minY else {return}
错误:
Initializer for conditional binding must have Optional type, not 'CGFloat'
以下方法中的第二个错误:
open func showCustom(_ title: String, subTitle: String, color: UIColor, icon: UIImage, closeButtonTitle:String?=nil, duration:TimeInterval=0.0, colorStyle: UInt=SCLAlertViewStyle.success.defaultColorInt, colorTextButton: UInt=0xFFFFFF, circleIconImage: UIImage? = nil, animationStyle: SCLAnimationStyle = .topToBottom) -> SCLAlertViewResponder {
var red: CGFloat = 0, green: CGFloat = 0, blue: CGFloat = 0, alpha: CGFloat = 0
color.getRed(&red, green: &green, blue: &blue, alpha: &alpha)
var colorAsUInt32 : UInt32 = 0
colorAsUInt32 += UInt32(red * 255.0) << 16 + UInt32(green * 255.0) << 8 + UInt32(blue * 255.0)
let colorAsUInt = UInt(colorAsUInt32)
return showTitle(title, subTitle: subTitle, duration: duration, completeText:closeButtonTitle, style: .success, colorStyle: colorAsUInt, colorTextButton: colorTextButton, circleIconImage: icon, animationStyle: animationStyle)
}
此行中的错误:
colorAsUInt32 += UInt32(red * 255.0) << 16 + UInt32(green * 255.0) << 8 + UInt32(blue * 255.0)
错误:
表达太复杂,无法在合理的时间内解决;考虑将表达式分解为不同的子表达式
答案 0 :(得分:1)
需要添加问号:
guard let endKeyBoardFrame = (userInfo[UIKeyboardFrameEndUserInfoKey] as? AnyObject).cgRectValue.minY else {return}
colorAsUInt32 += UInt32(red * 255.0) << 16
colorAsUInt32 += UInt32(green * 255.0) << 8
colorAsUInt32 += UInt32(blue * 255.0)