2014-12-27 65 views
0

我試圖將Apple生成的Keyboard Management文檔的代碼合併到我的應用程序中。到目前爲止,我已經能夠將Objective-C解析爲Swift,但是我遇到了一個問題。這是在上下文中(最後一行是在錯誤發生時):無法減去CGFloats

func keyboardWasShown(aNotification: NSNotification) { 
    let info = aNotification.userInfo as NSDictionary! 
    let kbSize = (info[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() 

    let contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize!.height, 0.0) 
    scrollView.contentInset = contentInsets 
    scrollView.scrollIndicatorInsets = contentInsets 

    let aRect = view.frame 
    aRect.size.height -= kbSize!.height //This line gives me trouble. 
} 

在該行,我明白,說:「不能調用錯誤消息‘ - =’類型的參數列表「( CGFloat,CGFloat)'「。有沒有解決這個問題的任何工作或有什麼我做錯了?


注:我曾嘗試他們兩個鑄造花車,但得到錯誤「不能調用‘INIT’類型‘($ T4,T9 $)’的參數列表」。當我將浮點數轉換爲不同的變量然後減去它們時,出現錯誤「無法用類型爲'(Float,Float)'」的參數列表調用' - ='。

回答

2

請將let aRect更改爲var aRect,變量可以更改。

+1

let用於定義常量和var來定義變量。 – gabbler 2014-12-27 17:17:22