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