Swift:当用户开始输入时,动画UItextField的宽度就像聊天应用程序一样

时间:2015-08-01 22:58:21

标签: ios swift uitableview uitextfield nslayoutconstraint

我想在用户开始输入时为文本字段设置动画以取左按钮空间,我厌倦了隐藏按钮并更改了constinet但没有任何效果

import UIKit

class ViewController: UIViewController,UITextFieldDelegate,UIAlertViewDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate,UIPopoverControllerDelegate {
    var chat = []


@IBOutlet var imageView: UIImageView!
@IBOutlet var textFieldWidth: NSLayoutConstraint!
@IBOutlet var chatTableview: UITableView!
@IBOutlet var textField: UITextField!
@IBOutlet var chatViewHeight: NSLayoutConstraint!
@IBOutlet var chatView: UIView!
@IBOutlet var sendButton: UIButton!
@IBOutlet var cameraButton: UIButton!



func textFieldDidBeginEditing(textField: UITextField) {
    self.view.layoutIfNeeded()
    UIView.animateWithDuration(0.1, animations: {

        self.chatViewHeight.constant = 300
        self.textFieldWidth.constant = 520
        self.view.layoutIfNeeded()
        self.sendButton.hidden = true

        }, completion: nil)

}
func textFieldDidEndEditing(textField: UITextField) {
    self.view.layoutIfNeeded()
    UIView.animateWithDuration(0.3, animations: {

        self.chatViewHeight.constant = 40
        self.view.layoutIfNeeded()

        }, completion: nil)
    self.sendButton.hidden = false

0 个答案:

没有答案