Fast user keyboard - display extra letters on the keyboard with a long press?

I have a custom keyboard extension in my application that is being developed using swift. They work great. I would like to add pop-up display functionality with extra characters when you long press on a keyboard, such as the default iOS keyboard. Something like that:

enter image description here

I searched a lot, but most of them did not receive an answer, and the response in Obj-C. I am not very good at Obj-C and am fairly new to fast programming.

I have already considered this , this and this . But they do not really help.

Any help would be really appreciated.

+6
3

1.
( , )

let btn: UIButton=UIButton(frame: CGRect(x: 5, y: 70, width: 30, height: 30))
     btn.setTitle("A", for: .normal)
    btn.setTitleColor(UIColor.black, for: .normal);
     self.view.addSubview(btn)

2. Long PressGesture

     let longGesture = UILongPressGestureRecognizer(target: self, action: #selector(longPress(sender:)))
longGesture.minimumPressDuration = 1.2
        btn.addGestureRecognizer(longGesture)

3. ,

PopUpView Some,

⚠️ . , CGPoint

  func longPress( sender: Any) {

            let longPressGesture = sender as! UILongPressGestureRecognizer

//Only run this code When State Begain
if longPressGesture.state != UIGestureRecognizerState.Began {
            return
     }
// if PopUpView is Already in added than remove and than  add
 if let checkView = self.view.viewWithTag(1001) as? UIView {
         // remove popView
        popUpView .removeFromSuperview()
   }

            let tapLocation = longPressGesture.location(in: self.view)


            popUpView=UIView(frame: CGRect(x: tapLocation.x-10, y: tapLocation.y-65, width: 150, height: 60))
            popUpView.backgroundColor=UIColor.orange
            popUpView.layer.cornerRadius=5
            popUpView.layer.borderWidth=2
            popUpView.tag=1001
            popUpView.layer.borderColor=UIColor.black.cgColor

            let btn0: UIButton=UIButton(frame: CGRect(x: 5, y: 5, width: 30, height: 30))
            btn0.setTitle("A1", for: .normal)
            btn0.setTitleColor(UIColor.black, for: .normal);
            btn0.layer.borderWidth=0.5
            btn0.layer.borderColor=UIColor.lightGray.cgColor

            popUpView.addSubview(btn0)

            let btn1: UIButton=UIButton(frame: CGRect(x: 35, y: 5, width: 30, height: 30))
            btn1.setTitle("A2", for: .normal)
            btn1.setTitleColor(UIColor.black, for: .normal);
            btn1.layer.borderWidth=0.5
            btn1.layer.borderColor=UIColor.lightGray.cgColor

            popUpView.addSubview(btn1)

            let btn2: UIButton=UIButton(frame: CGRect(x: 70, y: 5, width: 30, height: 30))
            btn2.setTitle("A2", for: .normal)
            btn2.setTitleColor(UIColor.black, for: .normal);
            btn2.layer.borderWidth=0.5
            btn2.layer.borderColor=UIColor.lightGray.cgColor

            popUpView.addSubview(btn2)

            btn0.addTarget(self, action: #selector(self.buttonAction(sender:)),
                             for: UIControlEvents.touchUpInside)
            btn1.addTarget(self, action: #selector(self.buttonAction(sender:)),
                           for: UIControlEvents.touchUpInside)
            btn2.addTarget(self, action: #selector(self.buttonAction(sender:)),
                           for: UIControlEvents.touchUpInside)

             self.view.addSubview(popUpView)


        }

4.

( , popUpView SuperView)

      func buttonAction( sender: Any) {

            // Do your Stuff Here


            //Than remove popView
            popUpView .removeFromSuperview()
        }

enter image description here

✅ . PopUpView UIBezierPath

, .

+1

Recognizer LongPress. , .

0

  • TextField, .
  • .
  • capitalization Min font size
  • Set capitalizationas words
  • Set all other default values ​​and basically keyboard typeNow create and run this and check with a letter s, eetc.

It will help you

0
source

All Articles