こんにちは。
首記の件ですが、下記のサイトを参考にして
LINEのようなTableViewとTextFieldを組み合わせた
チャット画面のようなUIを実装しています。
http://qiita.com/yuto_aka_ike/items/1d0cc3f7bc3aa4d4161a
その上で、上記サイト中の解説にもあるように通知で監視していた
Keyboardが出現するタイミングでCGAffineTransformMakeTranslationを
使用してKeyboardの高さ分だけ全体を上にずらす、というような
処理を書きました。
しかし、CGAffineTransformMakeTranslationでview全体が上にずれたあと
これによって隠れてしまったtableView部分を確認したいと思い
下に向かってスクロールしたのですが、隠れた部分が少しでも表示された時点(添付のスクリーンショットの赤い部分)で
エラーが出てしまい、アプリが落ちてしまいます。
エラーの原因で何か思い当たるものがある方いらっしゃいましたら
教えて頂ければ幸いです。
または、これを回避するための方策などで何か思いつくものがありましたら
教えて頂ければと思います。
以下、該当部分のコードを掲載いたします。
Swift
1//TableView。Autolayoutは上左右=self.viewから0, 下=textViewのbottomから-40 2 commentTableView = UITableView() 3 commentTableView.backgroundColor = ColorType.colorDefine(.backgroundGray)() 4 commentTableView.autoresizingMask = UIViewAutoresizing.FlexibleHeight 5 commentTableView.registerClass(CommentTableCell.self, forCellReuseIdentifier: "commentCell") 6 commentTableView.separatorInset = UIEdgeInsetsZero 7 commentTableView.separatorColor = ColorType.colorDefine(.separatorColor)() 8 commentTableView.delegate = self 9 commentTableView.dataSource = self 10 commentTableView.estimatedRowHeight = 80 11 commentTableView.rowHeight = UITableViewAutomaticDimension 12 commentTableView.separatorInset = UIEdgeInsetsZero 13 if self.commentTableView.respondsToSelector("layoutMargins") { 14 self.commentTableView.layoutMargins = UIEdgeInsetsZero 15 } 16 commentTableView.translatesAutoresizingMaskIntoConstraints = false 17 self.view.addSubview(commentTableView) 18
Swift
1//入力用のTextView。Autolayoutは左右下=self.viewから0, 上=tableViewのBottomから0 2 commentInput = UITextView() 3 commentInput.returnKeyType = UIReturnKeyType.Send 4 commentInput.backgroundColor = UIColor.whiteColor() 5 commentInput.textColor = textColor 6 commentInput.text = "コメント" 7 commentInput.font = UIFont.openSansFontOfSize(13) 8 commentInput.translatesAutoresizingMaskIntoConstraints = false 9 commentInput.delegate = self 10 self.view.addSubview(commentInput) 11
Swift
1//Keyboardが出た時にviewをずらす 2 func keyboardWillShow(notification: NSNotification?) { 3 4 let userInfo = notification!.userInfo! 5 6 let keyboardRect = (userInfo[UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue() 7 8 let duration:NSTimeInterval = notification?.userInfo?[UIKeyboardAnimationDurationUserInfoKey] as! Double 9 10 UIView.animateWithDuration(duration, animations: { 11 let transform = CGAffineTransformMakeTranslation(0, -keyboardRect.size.height) 12 self.view.transform = transform 13 },completion:nil) 14 } 15
エラー内容
回答1件
あなたの回答
tips
プレビュー