I want to create popup in iOS8 custom keyboard as shown below image.
我想在iOS8自定义键盘中创建弹出窗口,如下图所示。
Some code are working but can't access outer window of keyboard and occures issue as shown in below image-2
有些代码是工作的,但不能访问键盘的外窗口和出现的问题,如下图2所示。
2 个解决方案
#1
4
This what i have done in my custom Keyboard its working
这是我在定制键盘中所做的工作。
//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];
}
}
#2
4
From the Apple App Extension Programming guide:
来自苹果应用程序扩展编程指南:
Finally, it is not possible to display key artwork above the top edge of a custom keyboard’s primary view, as the system keyboard does on iPhone when you tap and hold a key in the top row.
最后,不可能在自定义键盘主视图的顶部边缘上显示键艺术品,就像iPhone上的系统键盘一样,当你点击并按住最上面一行的键时。
So it seems like you can't add pop-up outside the keyboard frame, so codelgnitor's answer is the best you can do.
看起来你不能在键盘框架外添加弹出窗口,所以codelgnitor的答案是你能做的最好的。
#1
4
This what i have done in my custom Keyboard its working
这是我在定制键盘中所做的工作。
//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];
}
}
#2
4
From the Apple App Extension Programming guide:
来自苹果应用程序扩展编程指南:
Finally, it is not possible to display key artwork above the top edge of a custom keyboard’s primary view, as the system keyboard does on iPhone when you tap and hold a key in the top row.
最后,不可能在自定义键盘主视图的顶部边缘上显示键艺术品,就像iPhone上的系统键盘一样,当你点击并按住最上面一行的键时。
So it seems like you can't add pop-up outside the keyboard frame, so codelgnitor's answer is the best you can do.
看起来你不能在键盘框架外添加弹出窗口,所以codelgnitor的答案是你能做的最好的。