From f17d232c1bc750deea773a1ad31ce92c1d348564 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Wed, 24 Jun 2015 14:54:34 +0800 Subject: [PATCH] show/hide of ConversationMoreView --- .../ConversationViewController.swift | 8 ++-- .../ConversationMoreView.swift | 39 +++++++++++++++++-- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/Yep/ViewControllers/Conversation/ConversationViewController.swift b/Yep/ViewControllers/Conversation/ConversationViewController.swift index b5a5fbd0..5b0f5f2c 100644 --- a/Yep/ViewControllers/Conversation/ConversationViewController.swift +++ b/Yep/ViewControllers/Conversation/ConversationViewController.swift @@ -911,17 +911,15 @@ class ConversationViewController: BaseViewController { moreView.showProfileAction = { self.performSegueWithIdentifier("showProfile", sender: nil) - moreView.removeFromSuperview() + moreView.hide() } moreView.reportAction = { self.report() - moreView.removeFromSuperview() + moreView.hide() } - moreView.frame = view.bounds - - view.window?.addSubview(moreView) + moreView.showInView(view) } func report() { diff --git a/Yep/Views/ConversationMore/ConversationMoreView.swift b/Yep/Views/ConversationMore/ConversationMoreView.swift index 11933a4c..8e03326a 100644 --- a/Yep/Views/ConversationMore/ConversationMoreView.swift +++ b/Yep/Views/ConversationMore/ConversationMoreView.swift @@ -135,6 +135,37 @@ class ConversationMoreView: UIView { var reportAction: (() -> Void)? + var tableViewBottomConstraint: NSLayoutConstraint? + + func showInView(view: UIView) { + + frame = view.bounds + + view.addSubview(self) + + layoutIfNeeded() + + UIView.animateWithDuration(0.3, delay: 0.0, options: .CurveEaseInOut, animations: { _ in + self.tableViewBottomConstraint?.constant = 0 + + self.layoutIfNeeded() + + }, completion: { finished in + }) + } + + func hide() { + + UIView.animateWithDuration(0.3, delay: 0.0, options: .CurveEaseInOut, animations: { _ in + self.tableViewBottomConstraint?.constant = 300 + + self.layoutIfNeeded() + + }, completion: { finished in + self.removeFromSuperview() + }) + } + override func didMoveToSuperview() { super.didMoveToSuperview() @@ -166,7 +197,9 @@ class ConversationMoreView: UIView { let tableViewConstraintsH = NSLayoutConstraint.constraintsWithVisualFormat("H:|[tableView]|", options: NSLayoutFormatOptions(0), metrics: nil, views: viewsDictionary) - let tableViewBottomConstraint = NSLayoutConstraint(item: tableView, attribute: .Bottom, relatedBy: .Equal, toItem: containerView, attribute: .Bottom, multiplier: 1.0, constant: 0) + let tableViewBottomConstraint = NSLayoutConstraint(item: tableView, attribute: .Bottom, relatedBy: .Equal, toItem: containerView, attribute: .Bottom, multiplier: 1.0, constant: 300) + + self.tableViewBottomConstraint = tableViewBottomConstraint let tableViewHeightConstraint = NSLayoutConstraint(item: tableView, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1.0, constant: 300) @@ -267,8 +300,8 @@ extension ConversationMoreView: UITableViewDataSource, UITableViewDelegate { break case .Cancel: - removeFromSuperview() - + hide() + default: break }