ScrollView swift编译错误

时间:2016-10-21 14:38:55

标签: ios uiscrollview swift2.3

我一直收到这个错误:

  

模糊使用' size

我到处寻找并尝试了一些技巧,但它不起作用,我不知道为什么。

import UIKit

class ScrollView: UIScrollView {
    var textField: UITextField!

    required init(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)!

        self.backgroundColor = UIColor(white: 1, alpha: 0)

    }

    func registerForKeyboardNotifications() {
        NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.keyboardWasShown), name: UIKeyboardDidShowNotification, object: nil)

        NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.keyboardWillBeHidden), name: UIKeyboardDidShowNotification, object: nil)
    }

    func keyboardWasShown(notification: NSNotification) {
        let info: NSDictionary = notification.userInfo!
        //HERE=>   let size = info.objectForKey(UIKeyboardFrameBeginUserInfoKey)?.size  /* THIS IS THE LINE OF THE ERROR */
        let insets = UIEdgeInsetsMake(0.0, 0.0, size!.height, 0.0)

        self.contentInset = insets
        self.scrollIndicatorInsets = insets

        var rect = self.frame
        rect.size.height -= size!.height

    }

    func keyboardWillBeHidden(notification: NSNotification) {
        let insets = UIEdgeInsetsZero
        self.contentInset = insets
        self.scrollIndicatorInsets = insets
    }

    func textFieldDidBeginEditing(textField: UITextField) {
        self.textField = textField
    }

    func textFieldDidEndEditing(textField: UITextField) {
        self.textField = nil
    }

    /**
     * Called when 'return' key pressed. return NO to ignore.
     */
    func textFieldShouldReturn(textField: UITextField) -> Bool {
        textField.resignFirstResponder()
        return true
    }

    /**
     * Called when the user click on the view (outside the UITextField).
     */
    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
        self.endEditing(true)
    }
}

这是我有错误的地方。我使用Swift 2.3和Xcode 8。 我试图改变我的功能但却犯了更多错误。

1 个答案:

答案 0 :(得分:0)

你必须强制转换objectForKey。 objectForKey返回类型“Any”,你想要来自CGRect类的方法。

selected.colnames <- colnames(log_mat)[grepl("AA(1)-Ib", 
                                       colnames(log_mat), fixed = TRUE)]