简体   繁体   中英

iOS - Pop-up custom subview after click

Maybe this is a simple problem, but I spend some time try to solve it and so far I failed.

I want to show custom view with a few of button after I clicked a block of text. I try to add and remove this view form subview but it's doesn't work.

Can you give me some tips about my problem?

Thank you for your help.

my code class ViewController: UIViewController, UITextFieldDelegate {

@IBOutlet weak var myTextField: UITextField!

@IBOutlet weak var simpleView: SimpleView!

override func viewDidLoad() {
    super.viewDidLoad()
    self.myTextField.delegate = self
    self.simpleView.removeFromSuperview()
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

func textFieldDidBeginEditing(textField: UITextField!) {
    println("works")
    self.view.addSubview(simpleView)
}

func textFieldDidEndEditing(textField: UITextField!) {
    println("works2")
}

}

您最好设置simpleView的hidden属性,而不是删除和添加视图。

put a container view in your main view and set the visibility hidden. when you want to show the popup, set the visibility to visible and load the view inside the container. To get the popup look and feel ,you can use a transformation to animate.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM