hide currentMenu when new menu show, vc disappear, or user scroll

This commit is contained in:
nixzhu
2015-07-23 15:41:18 +08:00
parent 3a546c8adc
commit 69f9060cdf
2 changed files with 24 additions and 10 deletions
@@ -109,6 +109,8 @@ class ConversationViewController: BaseViewController {
@IBOutlet weak var takePhotoButton: MessageTypeButton!
@IBOutlet weak var addLocationButton: MessageTypeButton!
var currentMenu: BubbleMenuView?
var originalNavigationControllerDelegate: UINavigationControllerDelegate?
var waverView: YepWaverView!
@@ -741,6 +743,12 @@ class ConversationViewController: BaseViewController {
}
}
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
currentMenu?.hide()
}
override func viewDidDisappear(animated: Bool) {
super.viewDidDisappear(animated)
@@ -2106,7 +2114,9 @@ extension ConversationViewController: UICollectionViewDataSource, UICollectionVi
cell.longPressAction = { [weak self] cell in
if let strongSelf = self {
self?.currentMenu?.hide()
if let strongSelf = self {
let copyItem = BubbleMenuView.Item(title: NSLocalizedString("Copy", comment: "")) { menu in
print("copy\n")
@@ -2185,7 +2195,7 @@ extension ConversationViewController: UICollectionViewDataSource, UICollectionVi
}
strongSelf.conversationCollectionView.deleteItemsAtIndexPaths([currentIndexPath])
}
//
strongSelf.lastTimeMessagesCount = strongSelf.messages.count
}
@@ -2199,7 +2209,9 @@ extension ConversationViewController: UICollectionViewDataSource, UICollectionVi
let arrowDirection: BubbleMenuView.ArrowDirection = CGRectGetMidY(textViewFrame) < 64 + 80 ? .Up : .Down
let menu = BubbleMenuView(arrowDirection: arrowDirection, items: [copyItem, deleteItem])
strongSelf.currentMenu = menu
menu.setTranslatesAutoresizingMaskIntoConstraints(false)
strongSelf.view.addSubview(menu)
@@ -2213,19 +2225,19 @@ extension ConversationViewController: UICollectionViewDataSource, UICollectionVi
case .Up:
vConstant += ceil(CGRectGetHeight(textViewFrame) * 0.5) - menu.offsetV
menuV = NSLayoutConstraint(item: menu, attribute: .Top, relatedBy: .Equal, toItem: strongSelf.view, attribute: .CenterY, multiplier: 1, constant: vConstant)
case .Down:
vConstant -= ceil(CGRectGetHeight(textViewFrame) * 0.5) - menu.offsetV
menuV = NSLayoutConstraint(item: menu, attribute: .Bottom, relatedBy: .Equal, toItem: strongSelf.view, attribute: .CenterY, multiplier: 1, constant: vConstant)
}
let centerXConstant = CGRectGetMidX(textViewFrame) - CGRectGetMidX(strongSelf.conversationCollectionView.frame)
let menuCenterX = NSLayoutConstraint(item: menu, attribute: .CenterX, relatedBy: .Equal, toItem: strongSelf.view, attribute: .CenterX, multiplier: 1, constant: centerXConstant)
NSLayoutConstraint.activateConstraints([menuV, menuCenterX])
}
}
@@ -2355,6 +2367,8 @@ extension ConversationViewController: UICollectionViewDataSource, UICollectionVi
func scrollViewDidScroll(scrollView: UIScrollView) {
pullToRefreshView.scrollViewDidScroll(scrollView)
currentMenu?.hide()
}
func scrollViewWillEndDragging(scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
+1 -1
View File
@@ -56,7 +56,7 @@ class BubbleMenuView: UIView {
let arrowHeight: CGFloat = 8
let buttonGap: CGFloat = 12
let offsetV: CGFloat = 1
let offsetV: CGFloat = 2
func makeUI() {