加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

swift – 来自'[NSObject:AnyObject]?’不相关的类型’NSD

发布时间:2020-12-14 04:35:29 所属栏目:百科 来源:网络整理
导读:这行让userInfo = notification.userInfo为! NSDictionary我得到一个警告:来自'[NSObject:AnyObject]?’不相关的类型’NSDictionary’总是失败 我尝试使用let userInfo = notification.userInfo作为!字典 NSObject:AnyObject将let userInfo = notifica
这行让userInfo = notification.userInfo为! NSDictionary我得到一个警告:来自'[NSObject:AnyObject]?’不相关的类型’NSDictionary’总是失败

我尝试使用let userInfo = notification.userInfo作为!字典< NSObject:AnyObject>将let userInfo = notification.userInfo替换为!的NSDictionary.但我收到一个错误:预计’>’完成通用参数列表.如何修复警告.

Xcode 7.1 OS X Yosemite

这是我的代码:

func keyboardWillShow(notification: NSNotification) {

    let userInfo = notification.userInfo as! NSDictionary //warning

    let keyboardBounds = (userInfo[UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue()
    let duration = (userInfo[UIKeyboardAnimationDurationUserInfoKey] as! NSNumber).doubleValue
    let keyboardBoundsRect = self.view.convertRect(keyboardBounds,toView: nil)

    let keyboardInputViewFrame = self.finishView!.frame

    let deltaY = keyboardBoundsRect.size.height

    let animations: (()->Void) = {

        self.finishView?.transform = CGAffineTransformMakeTranslation(0,-deltaY)
    }

    if duration > 0 {



    } else {

        animations()
    }


}

解决方法

NSNotification的userInfo属性已定义为(n可选)字典.

所以你根本不需要施放它,只需打开它.

func keyboardWillShow(notification: NSNotification) {
    if let userInfo = notification.userInfo {
        ...
    }
}

所有其余的代码应该按原样运行.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读