如何在iOS8自定义键盘中弹出像键盘字符一样的弹出窗口?

Sco*_*ive 16 iphone ios ios8 ios-app-extension custom-keyboard

我想在iOS8自定义键盘中创建弹出窗口,如下图所示.

想在iOS8中创建这种类型的键盘

有些代码正在工作但无法访问键盘的外窗并发生问题,如下图2所示

iOS8自定义键盘中的问题

cod*_*tor 5

这就是我在自定义键盘中所做的工作

//adding pop up when character is tapped
- (void)addPopupToButton:(UIButton *)button
{


    CGRect frame,frame1;
    if(self.view.frame.size.width == 320)
    {
        //Keyboard is in Portrait
        frame = CGRectMake(0, -25, 28, 43);
        frame1=CGRectMake(0, 0, 28, 43);

    }
    else{
        //Keyboard is in Landscape
        frame = CGRectMake(3, -25, 35, 43);
        frame1=CGRectMake(0, 10, 35, 43);

    }
   //create pop up view
    UIView *popUp=[[UIView alloc]initWithFrame:frame];

    //create a label to add to pop up view
    UILabel *text = [[UILabel alloc] init];

    //set frame for the label and set label title
    [text setFrame:frame1];
    [text setText:button.titleLabel.text];
    text.textAlignment=NSTextAlignmentCenter;
    [text setFont:[UIFont boldSystemFontOfSize:30]];
    text.backgroundColor=[UIColor whiteColor];

    //add label as popup view's subview
    [popUp addSubview:text];

    //add pop up view as button's subview
    [button addSubview:popUp];

}


//remove Pop up view
-(void)endPopUpForButton:(UIButton*)button
{
    if ([button subviews].count > 1)
    {
        [[[button subviews] objectAtIndex:1] removeFromSuperview];
    }
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

  • @ScorpianAlive,我遇到了同样的问题!现在我暂时将它设置为320.0 ..将为更大的弹出窗口工作. (2认同)
  • @ScorpianAlive,可以通过在视图中添加NSLayoutconstraint来更改自定义键盘的高度,请参阅本文档中的代码https://developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/ExtensibilityPG/ Keyboard.html但不在xcode beta 3和4中工作 (2认同)