how to realize iOS swift playgrounds virtual keyboard feature .

249 views Asked by At

Swift playground on iOS is good IDE for new programmers , and apple provide a virtual keyboard for programming , we can swipe the single button to input multi characters ,including “, ; : / “ …. , I want to realize the feature in my programme . How to implement this functionality? Using UIGestureRecognizerDelegate ? pan ? how to realized the animation that appeared in button when swipping ?

swift playgrounds virtual keyboard

here is my code:

import UIKit

class myViewController: UIViewController, UIGestureRecognizerDelegate {

@IBOutlet weak var mybutton1: UIButton!
override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    let gestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(buttonPressed(_:)))
    let moveRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(moved(_:)))
    let panRecognizer = UIPanGestureRecognizer(target: self, action: #selector(pan(_:)))
    let longgestureRecognizer = UILongPressGestureRecognizer(target: self, action:  #selector(longLabelPressed(_:)))
    longgestureRecognizer.minimumPressDuration = 1 //.001
    mybutton1.isUserInteractionEnabled = true;
    mybutton1.addGestureRecognizer(gestureRecognizer)
    mybutton1.addGestureRecognizer(moveRecognizer)
    mybutton1.addGestureRecognizer(panRecognizer)
    mybutton1.addGestureRecognizer(longgestureRecognizer)
}
override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}
func moved(_ recognizer:UILongPressGestureRecognizer){
     print("moved !!!!")
}
func pan(_ recognizer:UILongPressGestureRecognizer){
    print("pan !!!!")
}
func longLabelPressed(_ recognizer:UILongPressGestureRecognizer){
  //  if let label = recognizer.view as? UIButton {
        if recognizer.state == .began {
            //label.textColor = UIColor.red
             print("longlabelPressed begin !")
        }

        if recognizer.state == .ended {
            //label.textColor = UIColor.black
             print("longlabelPressed end  !")
        }
}
func buttonPressed(_ recognizer:UITapGestureRecognizer) {
   print("labelPressed  !")
}

}

//=============

0

There are 0 answers