【发布时间】:2017-04-08 08:58:28
【问题描述】:
有两个错误我被卡住了。当我在新的 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)
错误:
表达式过于复杂,无法在合理时间内解决;考虑将表达式分解为不同的子表达式
【问题讨论】:
-
查看stackoverflow.com/questions/25451001/… 的 Swift 2+3 代码以从通知中获取键盘大小。
-
请不要在一个问题中发布两个完全不相关的问题。
-
是的,很抱歉,我已经解决了大部分错误。只有这两个不能解决。对于我的第二个错误,无法识别