Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 越狱行为_Objective C_Uipopovercontroller - Fatal编程技术网

Objective c 越狱行为

Objective c 越狱行为,objective-c,uipopovercontroller,Objective C,Uipopovercontroller,我有一个弹出视图(计算器),每当文本字段开始编辑时就会显示。调用display方法的代码以及display方法本身发布在下面 -(BOOL)textFieldShouldBeginEditing:(UITextField *)textField { //the background color may have been yellow if someone tried to submit the form with a blank field textField.backgro

我有一个弹出视图(计算器),每当文本字段开始编辑时就会显示。调用display方法的代码以及display方法本身发布在下面

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {

    //the background color may have been yellow if someone tried to submit the form with a blank field
    textField.backgroundColor = [UIColor whiteColor];

    sender = @"text field";

    [self displayCalculator:textField.frame];

    return YES;
}
显示视图的方法是:

-(IBAction)displayCalculator:(CGRect)rect{

    calculator = [[CalculatorViewController alloc] initWithNibName:@"CalculatorViewController" bundle:nil];
    popoverController = [[[UIPopoverController alloc] initWithContentViewController:calculator] retain];

    [popoverController setPopoverContentSize:CGSizeMake(273.0f, 100.0f)];

    [popoverController presentPopoverFromRect:rect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

}
我的问题是:

1) 我怎样才能让府绸留下来?我希望用户能够单击textfield(首先显示弹出窗口的textfield),但当他们单击时,弹出窗口消失

2) 弹出窗口有时会以阻止文本字段的方式出现,我是否可以控制弹出窗口出现的位置?我当前正在传递文本字段的帧,但该帧似乎不起作用(问题1) 在displayCalculator方法中,您需要有一种方法来检查弹出窗口是否已经显示。现在,每次文本字段更新时,您都会重新绘制弹出窗口。您没有将textFieldDelegate调用更改为
textFieldDidBeginEditing

试试这个:

-(BOOL)textFieldDidBeginEditing:(UITextField *)textField {

    //the background color may have been yellow if someone tried to submit the form with a blank field
    textField.backgroundColor = [UIColor whiteColor];

    sender = @"text field";

    [self displayCalculator:textField.frame];

    return YES;
}

-(IBAction)displayCalculator:(CGRect)rect{

//We don't want to continually create a new instance of popoverController. So only if it is nil we create one. 
if (popoverController == nil)
    calculator = [[CalculatorViewController alloc] initWithNibName:@"CalculatorViewController" bundle:nil];
    popoverController = [[[UIPopoverController alloc] initWithContentViewController:calculator] retain];

    [popoverController setPopoverContentSize:CGSizeMake(273.0f, 100.0f)];
}

//Check to make sure it isn't already showing. If it's not, then we show it. 
if (!popoverController.popoverVisible) {
    [popoverController presentPopoverFromRect:rect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}

}
编辑

正如斯金尼指出的(我应该提到)。只要你在外面碰一下,爆米花就会消失。这就是textFieldDelegate更改为textFieldDidBeginEditing的原因


检查文档,看看是否有方法或属性可以解决所需的任务或功能()

似乎对于第一期,您应该查看
passthroughview
属性:

直通视图

用户可以在打开popover时与之交互的视图数组 看得见@属性(非原子,副本)NSArray*直通视图 讨论

当popover处于活动状态时,通常会停止与其他视图的交互 禁用,直到弹出框被解除。指定视图数组 此属性允许用户处理popover之外的点击 相应的视图

对于第二个问题(包括文本区域),您可以偏移textField.frame以定义一个新的
CGRect
,供popoverController用作其锚定

CGRect targetRect = CGRectOffset(textField.frame, n, n);