Iphone UIApplication beginIgnoringInteractionEvents]溢出。忽略
我正在尝试动态创建Iphone UIApplication beginIgnoringInteractionEvents]溢出。忽略,iphone,ios,objective-c,xcode,cocoa-touch,Iphone,Ios,Objective C,Xcode,Cocoa Touch,我正在尝试动态创建UITextField,然后单击textField试图显示picker视图,但如何获得上述错误。 它在循环中运行,除非我停止应用程序,否则错误不会停止 代码 -(void)textFieldDidBeginEditing:(UITextField *)textField { CGRect textFieldRect = [self.view.window convertRect:textField.bounds fromView:textField];
UITextField
,然后单击textField试图显示picker视图,但如何获得上述错误。
它在循环中运行,除非我停止应用程序,否则错误不会停止
代码
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
CGRect textFieldRect =
[self.view.window convertRect:textField.bounds fromView:textField];
CGRect viewRect =
[self.view.window convertRect:self.view.bounds fromView:self.view];
CGFloat midline = textFieldRect.origin.y + 0.5 * textFieldRect.size.height;
CGFloat numerator =
midline - viewRect.origin.y
- MINIMUM_SCROLL_FRACTION * viewRect.size.height;
CGFloat denominator =
(MAXIMUM_SCROLL_FRACTION - MINIMUM_SCROLL_FRACTION)
* viewRect.size.height;
CGFloat heightFraction = numerator / denominator;
if (heightFraction < 0.0)
{
heightFraction = 0.0;
}
else if (heightFraction > 1.0)
{
heightFraction = 1.0;
}
UIInterfaceOrientation orientation =
[[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationPortrait ||
orientation == UIInterfaceOrientationPortraitUpsideDown)
{
animatedDistance = floor(PORTRAIT_KEYBOARD_HEIGHT * heightFraction);
}
else
{
animatedDistance = floor(LANDSCAPE_KEYBOARD_HEIGHT * heightFraction);
}
CGRect viewFrame = self.view.frame;
viewFrame.origin.y -= animatedDistance;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION];
[self.view setFrame:viewFrame];
[UIView commitAnimations];
if (textField.tag < 10) {
if ([[datatypeArray objectAtIndex:textField.tag] isEqualToString:@"Currency"])
{
[self showpicker:textField];
}
else if([[datatypeArray objectAtIndex:textField.tag ] isEqualToString:@"Date" ])
{
[self showpicker:textField];
}
else if([[datatypeArray objectAtIndex:textField.tag] isEqualToString:@"Text"])
{
}
}
else
{
[self showpicker:textField];
}
}
-(void)showpicker:(UITextField *)textfield
{
[textfield resignFirstResponder];
if (textfield.tag >= 10 ) {
currentTextField=textfield;
pickerArray=arraycurrency;
actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
[actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
CGRect pickerFrame = CGRectMake(0, 40, 0, 0);
pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame];
pickerView.showsSelectionIndicator = YES;
pickerView.dataSource = self;
pickerView.delegate = self;
[actionSheet addSubview:pickerView];
UIToolbar *pickerToolbar;
pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
pickerToolbar.barStyle = UIBarStyleBlackOpaque;
[pickerToolbar sizeToFit];
NSMutableArray *barItems = [[NSMutableArray alloc] init];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
[barItems addObject:flexSpace];
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonPressed:)];
[barItems addObject:doneBtn];
UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelButtonPressed:)];
[barItems addObject:cancelBtn];
[pickerToolbar setItems:barItems animated:YES];
[actionSheet addSubview:pickerToolbar];
[actionSheet addSubview:pickerView];
[actionSheet showInView:self.view];
[actionSheet showInView:[UIApplication sharedApplication].keyWindow];
[actionSheet setBounds:CGRectMake(0, 0, 320, 485)];
}
else if ([[datatypeArray objectAtIndex:textfield.tag ] isEqualToString:@"Date" ])
{
[textfield resignFirstResponder];
currentTextField=textfield;
actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
pickerDateView = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 44, 0, 0)];
pickerDateView.datePickerMode = UIDatePickerModeDate;
pickerDateView.hidden = NO;
pickerDateView.date = [NSDate date];
pickerDateView.userInteractionEnabled=YES;
pickerDateView.timeZone=[NSTimeZone localTimeZone];
UIToolbar *pickerToolbar;
pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
pickerToolbar.barStyle = UIBarStyleBlackOpaque;
[pickerToolbar sizeToFit];
NSMutableArray *barItems = [[NSMutableArray alloc] init];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
[barItems addObject:flexSpace];
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonPressed:)];
[barItems addObject:doneBtn];
UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelButtonPressed:)];
[barItems addObject:cancelBtn];
[pickerToolbar setItems:barItems animated:YES];
[actionSheet addSubview:pickerToolbar];
[actionSheet addSubview:pickerDateView];
[actionSheet showInView:[UIApplication sharedApplication].keyWindow];
[actionSheet setBounds:CGRectMake(0,0,320, 464)];
}
else if ( [[datatypeArray objectAtIndex:textfield.tag] isEqualToString:@"Text"])
{
[textfield becomeFirstResponder];
}
else if((textfield.tag==0 || textfield.tag==1 || textfield.tag==2 || textfield.tag==3 || textfield.tag==4) &&
[[datatypeArray objectAtIndex:textfield.tag] isEqualToString:@"Currency"]);
{
[textfield becomeFirstResponder];
}
}
-(void)textFieldDidBeginEditing:(UITextField*)textField
{
CGRect textFieldRect=
[self.view.window convertRect:textField.bounds fromView:textField];
CGRect viewRect=
[self.view.window convertRect:self.view.fromView:self.view];
CGFloat midline=textFieldRect.origin.y+0.5*textFieldRect.size.height;
CGFloat分子=
中线-viewRect.origin.y
-最小滚动分数*viewRect.size.height;
浮点分母=
(最大滚动分数-最小滚动分数)
*viewRect.size.height;
CGFloat heightFraction=分子/分母;
如果(高度分数<0.0)
{
高度分数=0.0;
}
否则如果(高度分数>1.0)
{
高度分数=1.0;
}
界面定向=
[[UIApplication sharedApplication]statusBarOrientation];
如果(方向==UIInterfaceOrientationParative||
方向==UIInterfaceOrientationGraphitalUpsideDown)
{
动画距离=地板(纵向\键盘\高度*高度分数);
}
其他的
{
动画距离=地板(横向键盘高度*高度分数);
}
CGRect viewFrame=self.view.frame;
viewFrame.origin.y-=动画距离;
[UIView beginAnimations:nil上下文:NULL];
[UIView setAnimationBeginsFromCurrentState:是];
[UIView设置动画持续时间:键盘动画持续时间];
[self.view setFrame:viewFrame];
[UIView委员会];
如果(textField.tag<10){
if([[datatypeArray objectAtIndex:textField.tag]IseQualtString:@“Currency”])
{
[自显示选择器:textField];
}
else if([[datatypeArray objectAtIndex:textField.tag]IsequalString:@“Date”])
{
[自显示选择器:textField];
}
else if([[datatypeArray objectAtIndex:textField.tag]IsequalString:@“Text”])
{
}
}
其他的
{
[自显示选择器:textField];
}
}
-(void)showpicker:(UITextField*)textfield
{
[textfield resignFirstResponder];
如果(textfield.tag>=10){
currentTextField=textfield;
选择器阵列=阵列电流;
actionSheet=[[UIActionSheet alloc]initWithTitle:nil委托:self-cancelButtontile:nil-destructiveButtontile:nil-otherButtontiles:nil];
[actionSheet setActionSheetStyle:UIActionSheetStyleBlack半透明];
CGRect pickerFrame=CGRectMake(0,40,0,0);
pickerView=[[UIPickerView alloc]initWithFrame:pickerFrame];
pickerView.showsSelectIndicator=是;
pickerView.dataSource=self;
pickerView.delegate=self;
[actionSheet addSubview:pickerView];
UIToolbar*选择器Toolbar;
pickerToolbar=[[UIToolbar alloc]initWithFrame:CGRectMake(0,0320,44)];
pickerToolbar.barStyle=UIBarStyleBlack不透明;
[pickerToolbar sizeToFit];
NSMUTABLEARRY*barItems=[[NSMUTABLEARRY alloc]init];
UIBarButtonItem*flexSpace=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace目标:自我操作:nil];
[barItems addObject:flexSpace];
UIBarButtonItem*doneBtn=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:uiBarButtonSystemItem目标:自我操作:@selector(doneButtonPressed:)];
[barItems addObject:doneBtn];
UIBarButtonItem*cancelBtn=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCancel目标:自我操作:@selector(cancelButtonPressed:)];
[barItems addObject:cancelBtn];
[pickerToolbar设置项:barItems动画:是];
[actionSheet addSubview:pickerToolbar];
[actionSheet addSubview:pickerView];
[actionSheet showInView:self.view];
[actionSheet showInView:[UIApplication sharedApplication].keyWindow];
[actionSheet setBounds:CGRectMake(0,0,320,485)];
}
else if([[datatypeArray objectAtIndex:textfield.tag]IsequalString:@“Date”])
{
[textfield resignFirstResponder];
currentTextField=textfield;
actionSheet=[[UIActionSheet alloc]initWithTitle:nil委托:self-cancelButtontile:nil-destructiveButtontile:nil-otherButtontiles:nil];
pickerDateView=[[UIDatePicker alloc]initWithFrame:CGRectMake(0,44,0,0)];
pickerDateView.datePickerMode=UIDatePickerModeDate;
pickerDateView.hidden=否;
pickerDateView.date=[NSDate日期];
pickerDateView.userInteractionEnabled=YES;
pickerDateView.timeZone=[NSTimeZone localTimeZone];
UIToolbar*选择器Toolbar;
pickerToolbar=[[UIToolbar alloc]initWithFrame:CGRectMake(0,0320,44)];
pickerToolbar.barStyle=UIBarStyleBlack不透明;
[pickerToolbar sizeToFit];
NSMUTABLEARRY*barItems=[[NSMUTABLEARRY alloc]init];
UIBarButtonItem*flexSpace=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace目标:自我操作:nil];
[barItems addObject:flexSpace];
UIBarButtonItem*doneBtn=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:uiBarButtonSystemItem目标:自我操作:@selector(doneButtonPressed:)];
[barItems addObject:doneBtn];
UIBarButtonItem*cancelBtn=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCancel目标:自我操作:@selector(cancelButtonPressed:)];
[barItems addObject:cancelBt
-(void)textFieldDidBeginEditing:(UITextField *)sender
{
[self willDisplayPickerView];
}
- (void)willDisplayPickerView
{
// Init the picker view.
pickerView = [[UIPickerView alloc] init];
// Set the delegate and datasource. Don't expect picker view to work
// correctly if you don't set it.
[pickerView setDataSource: self];
[pickerView setDelegate: self];
// Set the picker's frame. We set the y coordinate to 50px.
[pickerView setFrame: CGRectMake(xPoint, 50.0f, pickerWidth, 200.0f)];
// Before we add the picker view to our view, let's do a couple more
// things. First, let the selection indicator (that line inside the
// picker view that highlights your selection) to be shown.
pickerView.showsSelectionIndicator = YES;
// Allow us to pre-select the third option in the pickerView.
[pickerView selectRow:2 inComponent:0 animated:YES];
// OK, we are ready. Add the picker in our view.
[self.view addSubview: pickerView];
}