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

时间:2014-08-19 07:29:21

标签: ios iphone ios8 ios-app-extension custom-keyboard

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

Want to create this type of keyboard in iOS8

某些代码正在运行但无法访问键盘的外窗并发生问题,如下图所示

Issue in iOS8 Custom Keyboard

2 个答案:

答案 0 :(得分: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];
    }
}

enter image description here

答案 1 :(得分:4)

来自Apple App Extension Programming guide

  

最后,无法在顶部边缘上方显示关键作品   自定义键盘的主视图,如系统键盘所用   点击并按住顶行中的某个键时的iPhone。

因此,您似乎无法在键盘框架外添加弹出窗口,因此您可以做出最好的代码答案。

相关问题