如何允许自定义UIView上的两次点击来显示和隐藏弹出窗口?

时间:2015-10-30 15:09:51

标签: ios swift uiview

我有三个自定义UIViews,它们是小圆圈,放在屏幕上的不同位置。如果单击任何圆圈,则会显示一个弹出窗口。有两种情况:
1.如果我点击一个圆圈,它会显示一个弹出窗口,如果我再次点击它,它会隐藏弹出窗口和圆圈。 2.如果我点击一个圆圈,它将显示一个弹出窗口,但是如果我没有再次点击它而是点击另一个圆圈,它应该显示第二个圆圈的弹出窗口,并且应该隐藏第一个弹出框和圆圈。 总之,一次只能看到一个弹出窗口。我设法实现了第一个场景,但是与第二个场景挣扎。这是代码:

   func showPopover(sender:UITapGestureRecognizer){
    if sender.view == hotSpotOne{

        let description = "Search \n" + "Search equities to view the order book and market prints for specific moments in time."
        let heading = "Search"
        let wordRange = (description as NSString).rangeOfString(heading)
        let attributedString = NSMutableAttributedString(string: description, attributes: [NSFontAttributeName: UIFont.systemFontOfSize(12)])
        attributedString.setAttributes([NSFontAttributeName: UIFont.boldSystemFontOfSize(12)], range: wordRange)
        self.helpTip!.showAttributedText(attributedString, direction: .Down, maxWidth: 200, inView: self.view, fromFrame: self.hotSpotOne.frame)

        if self.helpTip!.isVisible {
            self.helpTip!.hide()
            hotSpotOne.removeFromSuperview()
            return
        }  
    }
    else if sender.view == hotSpotTwo{

        let description = "Market Events \n" + "Swipe to view recent market anomalies selected by Surveyor's analytics team."
        let heading = "Market Events"
        let wordRange = (description as NSString).rangeOfString(heading)
        let attributedString = NSMutableAttributedString(string: description, attributes: [NSFontAttributeName: UIFont.systemFontOfSize(12)])
        attributedString.setAttributes([NSFontAttributeName: UIFont.boldSystemFontOfSize(12)], range: wordRange)
        self.helpTip!.showAttributedText(attributedString, direction: .Down, maxWidth: 200, inView: self.view, fromFrame: self.hotSpotTwo.frame)



        if self.helpTip!.isVisible {
            self.helpTip!.hide()
            hotSpotTwo.removeFromSuperview()
            return
        }
    }
    else {

        let description = "Get More Data \n" + "Learn More about how Surveyor's professional products can benefit your financial institution."
        let heading = "Get More Data"
        let wordRange = (description as NSString).rangeOfString(heading)
        let attributedString = NSMutableAttributedString(string: description, attributes: [NSFontAttributeName: UIFont.systemFontOfSize(12)])
        attributedString.setAttributes([NSFontAttributeName: UIFont.boldSystemFontOfSize(12)], range: wordRange)
        self.helpTip!.showAttributedText(attributedString, direction: .Up, maxWidth: 200, inView: self.view, fromFrame: self.hotSpotThree.frame)

        if self.helpTip!.isVisible {
            self.helpTip!.hide()
            hotSpotThree.removeFromSuperview()
            return
        }

    }

}

我正在使用AMPopTip库来显示popovers。感谢任何帮助,谢谢!

0 个答案:

没有答案