有兩個錯誤我卡住了。我得到這個錯誤,當我打開我的項目在新的xcode 8 swift 3.0我不知道如何糾正這個錯誤。我已經解決了一些其他的錯誤。但是爲了上面提到的錯誤,在這裏發現了這個問題。有條件綁定的初始化必須有可選類型,而不是'CGFloat'
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)
錯誤:
表達過於複雜,在合理的時間內得到解決;考慮分手的表達成不同的子表達式
的可能的複製[條件結合初始化程序必須有可選的類型,而不是「字符串」(HTTP://計算器.com/questions/32768274/initializer-for-conditional-binding-must-have-optional-type-not-string) –
看看http://stackoverflow.com/questions/25451001/getting-keyboard-size-從swift 2 + 3代碼的userinfo-in-swift中獲取通知的鍵盤大小。 –
請不要在一個問題中發佈兩個完全無關的問題。 –