Implémenter Keyboard Keyboard Animation dans iOS 8 Extension du keyboard

Je voudrais requestr comment mettre en œuvre l'animation pop lorsque vous tenez une touche de keyboard pour l'extension des keyboards iOS 8. Je sais comment assigner le geste d'appui long sur chaque touche mais je ne sais pas comment animer les touches pour présenter d'autres caractères dans cette touche spécifique. Toute aide serait appréciée. Merci! 🙂

EDIT: J'ai vu cette question similaire posée ici mais la différence est qu'il était capable de créer les animations pop.

EDIT 2: J'ai vu une autre question similaire posée ici, mais ils diffèrent sur la façon dont il ressemble à l'apparence par défaut sur le keyboard standard.

touche de clavier étendue

EDIT 3: J'ai été capable d'atteindre mon comportement désiré en tapant sur les touches du keyboard. J'ai juste besoin de savoir comment dessiner correctement la vue key développée. Ci-joint sont des images pour reference. Le premier est ce que nous avons accompli jusqu'à présent. J'aimerais savoir comment dessiner cette lettre F et la traduire ensuite en UIView .

progrès en cours

EDIT 4: J'ai été capable de créer la vue pop key mais pas dans la forme ou la couche que je voulais qui ressemble à la touche pop standard du keyboard. Ici c'est pour reference:

vue pop actuelle

EDIT 5: J'ai essayé la version démo de PaintCode et elle a généré le code ci-dessous. Ceci est dans ma méthode drawRect sur ma vue personnalisée. La largeur de mes keys est généralement de 26,0 et la hauteur de 39,0. J'utilise aussi Objective-C btw.

  UIBezierPath* bezierPath = UIBezierPath.bezierPath; [bezierPath moveToPoint: CGPointMake(26, 5.12)]; [bezierPath addLineToPoint: CGPointMake(26, 18.03)]; [bezierPath addCurveToPoint: CGPointMake(23.05, 22.41) controlPoint1: CGPointMake(26, 19.88) controlPoint2: CGPointMake(24.82, 21.51)]; [bezierPath addCurveToPoint: CGPointMake(19.62, 25.27) controlPoint1: CGPointMake(22.05, 23.24) controlPoint2: CGPointMake(20.79, 24.3)]; [bezierPath addCurveToPoint: CGPointMake(19.62, 39.95) controlPoint1: CGPointMake(19.62, 30.82) controlPoint2: CGPointMake(19.62, 39.95)]; [bezierPath addCurveToPoint: CGPointMake(17.17, 42) controlPoint1: CGPointMake(19.62, 41.08) controlPoint2: CGPointMake(18.52, 42)]; [bezierPath addLineToPoint: CGPointMake(8.83, 42)]; [bezierPath addCurveToPoint: CGPointMake(6.38, 39.95) controlPoint1: CGPointMake(7.48, 42) controlPoint2: CGPointMake(6.38, 41.08)]; [bezierPath addCurveToPoint: CGPointMake(6.38, 25.33) controlPoint1: CGPointMake(6.38, 39.95) controlPoint2: CGPointMake(6.38, 30.89)]; [bezierPath addCurveToPoint: CGPointMake(5.67, 24.74) controlPoint1: CGPointMake(6.15, 25.14) controlPoint2: CGPointMake(5.91, 24.94)]; [bezierPath addCurveToPoint: CGPointMake(5.37, 24.49) controlPoint1: CGPointMake(5.57, 24.66) controlPoint2: CGPointMake(5.47, 24.57)]; [bezierPath addLineToPoint: CGPointMake(5.32, 24.45)]; [bezierPath addCurveToPoint: CGPointMake(2.75, 22.3) controlPoint1: CGPointMake(4.41, 23.69) controlPoint2: CGPointMake(3.5, 22.93)]; [bezierPath addCurveToPoint: CGPointMake(1.02, 20.85) controlPoint1: CGPointMake(2.06, 21.92) controlPoint2: CGPointMake(1.47, 21.43)]; [bezierPath addCurveToPoint: CGPointMake(0.98, 20.82) controlPoint1: CGPointMake(0.99, 20.83) controlPoint2: CGPointMake(0.98, 20.82)]; [bezierPath addCurveToPoint: CGPointMake(0, 18.03) controlPoint1: CGPointMake(0.36, 20.02) controlPoint2: CGPointMake(-0, 19.06)]; [bezierPath addLineToPoint: CGPointMake(0, 5.12)]; [bezierPath addCurveToPoint: CGPointMake(2.48, 1.01) controlPoint1: CGPointMake(0, 3.44) controlPoint2: CGPointMake(0.97, 1.94)]; [bezierPath addCurveToPoint: CGPointMake(6.05, 0) controlPoint1: CGPointMake(3.48, 0.39) controlPoint2: CGPointMake(4.71, 0.02)]; [bezierPath addLineToPoint: CGPointMake(6.13, 0)]; [bezierPath addLineToPoint: CGPointMake(19.87, 0)]; [bezierPath addCurveToPoint: CGPointMake(26, 5.12) controlPoint1: CGPointMake(23.25, 0) controlPoint2: CGPointMake(26, 2.29)]; [bezierPath closePath]; [[UIColor redColor] setFill]; [bezierPath fill]; 

Le problème est, il ressemble à ceci:

entrez la description de l'image ici

Si seulement je peux le rendre assez grand pour le faire comme le keyboard par défaut, alors ça va marcher.

J'utiliserais un CAShapeLayer .

Vous pouvez réinitialiser la forme de la couche de forme à tout moment, et même animer le changement de forme pour faire quelque chose de plus élaboré que la version Apple.

Voici le code pour un terrain de jeu qui montre une version simple d'une class qui accomplit ceci:

 import UIKit class KeyPopView: UIView { static let widthPadding : CGFloat = 5.0 static let leftOffset : CGFloat = -5.0 init(frame: CGRect, letters: [Ssortingng]) { super.init(frame: frame) addLetters(letters) } required init(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } override class func layerClass() -> AnyClass { return CAShapeLayer.self } override func layoutSubviews() { super.layoutSubviews() var run : CGFloat = KeyPopView.widthPadding for l in labels { let s = sizeForLabel(l) let mh = maxHeight(labels) l.frame = CGRectMake(run, -mh, s.width, s.height) run += s.width + KeyPopView.widthPadding } } var shapeLayer: CAShapeLayer { get { return layer as! CAShapeLayer } } var path: CGPathRef { get { return shapeLayer.path } set(nv) { shapeLayer.shadowPath = nv shapeLayer.path = nv } } var labels : [UILabel] = [] { willSet { for l in labels { l.removeFromSuperview() } } didSet { for l in labels { addSubview(l) } path = keyPopPath(labels, cornerRadius: cornerRadius).CGPath } } var cornerRadius : CGFloat = 4 { didSet { path = keyPopPath(labels, cornerRadius: cornerRadius).CGPath } } override var backgroundColor: UIColor? { set(newValue) { shapeLayer.fillColor = newValue?.CGColor } get { return UIColor(CGColor: shapeLayer.fillColor) } } func keyPopPath(ls : [UILabel], cornerRadius: CGFloat) -> UIBezierPath { let radius = CGSizeMake(cornerRadius, cornerRadius); let f = CGRectMake(0, 0, frame.width + KeyPopView.widthPadding * 2, frame.height) let mh = maxHeight(ls) var b = UIBezierPath(roundedRect: CGRectMake(KeyPopView.leftOffset, -mh, widthForLabels(ls) - KeyPopView.leftOffset + KeyPopView.widthPadding, mh), byRoundingCorners: UIRectCorner.AllCorners, cornerRadii: radius) b.appendPath(UIBezierPath(roundedRect: f, byRoundingCorners: UIRectCorner.BottomLeft | UIRectCorner.BottomRight, cornerRadii: radius)) return b } func addLetters(letters : [Ssortingng]) { labels = letters.map({(s: Ssortingng) -> UILabel in var l = UILabel() l.text = s return l }) } func widthForLabels(ls: [UILabel]) -> CGFloat { return ls.reduce(0, combine: {(t, l) in t + sizeForLabel(l).width + KeyPopView.widthPadding}) + KeyPopView.widthPadding } func sizeForLabel(l: UILabel) -> CGSize { return l.text!.sizeWithAtsortingbutes([NSFontAtsortingbuteName: l.font]) } func maxHeight(ls: [UILabel]) -> CGFloat { var m : CGFloat = 0; for l in ls { let h = sizeForLabel(l).height m = m > h ? m : h } return m } } //start with a gray background view var ba = UIView(frame: CGRectMake(0, 0, 300, 300)) ba.backgroundColor = UIColor.grayColor() //add a mock "key" let key = UILabel() key.text = "a" key.textAlignment = NSTextAlignment.Center key.backgroundColor = UIColor.whiteColor() let size = key.text!.sizeWithAtsortingbutes([NSFontAtsortingbuteName: key.font]) key.frame = CGRectMake(5, 0, size.width + 10, size.height) key.layer.cornerRadius = 5 key.center = ba.center ba.addSubview(key) //add the initial keypop key.hidden = true // the key's rounded corners aren't showing up correctly in my playground preview -- this shouldn't be necessary var k = KeyPopView(frame: CGRectMake(0, 0, size.width, size.height), letters: ["a"]) k.backgroundColor = UIColor.whiteColor() ba.addSubview(k) k.center = CGPointMake(key.center.x - 5, key.center.y) ba //demonstrates resizing of the keypop view to accomdate more letters k.addLetters(["a", "b", "c", "d", "e"]) ba 

Dans sa forme actuelle, cette class a de nombreux problèmes:

  • Les lettres sont légèrement décinputs
  • Le cadre de la vue est utilisé comme le cadre de la touche à partir de laquelle la pop commence, pas le cadre réel de ce qui est dessiné.
  • Il ne prend en charge que les touches de gauche
  • Plusieurs options sont déballées de force
  • La "tige" du path utilisé n'a pas de coins intérieurs arrondis comme le keyboard système
  • Les variables sont nommées pour la brièveté, pas la clarté

Cependant, cela devrait fournir une bonne base pour atteindre ce que vous voulez.

Peut-être plus facile de faire l'animation dans photoshop ou quelque chose qui peut produire les images d'animation en tant qu'images séparées, puis animer un UIImageView ( docs ).

Il suffit donc d'animer l'arrière-plan de la chose popup de la manière mentionnée ci-dessus, puis de faire UILabel la lettre avec l'animation, ou d' UILabel soigneusement UILabel avec l'animation d'arrière-plan