【发布时间】:2014-10-12 05:23:42
【问题描述】:
我想在 iOS8 自定义键盘中创建弹出窗口,如下图所示。
一些代码正在运行,但无法访问键盘的外部窗口,并出现如下图 2 所示的问题
【问题讨论】:
标签: ios iphone ios8 ios-app-extension custom-keyboard
我想在 iOS8 自定义键盘中创建弹出窗口,如下图所示。
一些代码正在运行,但无法访问键盘的外部窗口,并出现如下图 2 所示的问题
【问题讨论】:
标签: ios iphone ios8 ios-app-extension custom-keyboard
这是我在自定义键盘中所做的工作
//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];
}
}
【讨论】:
来自Apple App Extension Programming guide:
最后,无法在顶部边缘上方显示关键图稿 自定义键盘的主要视图,就像系统键盘一样 iPhone 当您点击并按住顶行中的一个键时。
所以看起来你不能在键盘框架之外添加弹出窗口,所以codelgnitor的答案是你能做的最好的。
【讨论】: