0
你好我試圖改變一個按鈕的高度設置爲inputAccessoryView一旦我點擊它。動畫inputAccessoryView的高度Swift
不幸的是,它似乎只能改變位置,而不是高度。
任何人都可以幫我嗎?在我的代碼下面。
謝謝!
import UIKit
class ViewController: UIViewController, UITextFieldDelegate {
@IBOutlet var textField: UITextField!
var SendButton: UIButton = UIButton.buttonWithType(UIButtonType.Custom) as UIButton
override func viewDidLoad() {
super.viewDidLoad()
SendButton.frame = CGRectMake(0, 0, UIScreen.mainScreen().applicationFrame.width, 30)
SendButton.backgroundColor = UIColor(red: 184/255.0, green: 56/255.0, blue: 56/255.0, alpha: 1)
SendButton.setTitle("Send", forState: .Normal)
SendButton.addTarget(self, action: "sendNotification", forControlEvents: UIControlEvents.AllEvents)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func sendNotification(){
UIView.animateWithDuration(1, animations: {
self.SendButton.frame = CGRectMake(0, -340, UIScreen.mainScreen().applicationFrame.width, 30)
self.SendButton.backgroundColor = UIColor(red: 300/255.0, green: 56/255.0, blue: 56/255.0, alpha: 1)
self.SendButton.setTitle("Hello", forState: .Normal)
})
}
func textFieldDidBeginEditing(textField: UITextField) {
textField.inputAccessoryView = self.SendButton
}
}
您好,感謝您的回覆。但不幸的是,即使改變高度也無濟於事。高度仍然保持不變。你有什麼想法,爲什麼?謝謝 –
你可以在 – rakeshbs
這個問題上更新你當前的代碼我已經通過使用另一個視圖添加了高度作爲inputaccessoryview並添加了按鈕來解決問題。檢查代碼。 https://gist.github.com/rakeshbs/539827925df923e41afe – rakeshbs