The user interface is programmatically generated in my application. In the user interface, I have few buttons and texboxes . I developed a custom uidatapicker object that appears on top and animates to the middle of the screen. When the uidatapicker pops up, I draw another UIView (called the helper view) with the screen size, so all other uiobject on the screen except the uidatepicker become disabled. But when uidatepicker animates the button in the user interface, it moves to another place. I also have three buttons in my interface. This happens with only one button (one UIButon in a UIView). The other two buttons are fine. There is also no significant difference between these buttons, except for the button text.
- I deleted the previously described view (auxiliary view), but still a problem arises.
- I need to know why this is happening, how to prevent it.
- I also have many other pages that work great.
Code
-(void)openEditDateTime:(UIDatePickerMode) mode { if ([clientView viewWithTag:9]) { [self cancelPressed]; } CGRect toolbarTargetFrame = CGRectMake((clientView.frame.size.width/2)-160, (clientView.frame.size.height/2)+91, 320, 44); CGRect datePickerTargetFrame = CGRectMake((clientView.frame.size.width/2)-160, (clientView.frame.size.height/2)-125, 320, 216); backgroundView = [[UIView alloc] initWithFrame:clientView.bounds]; backgroundView.alpha = 0; backgroundView.backgroundColor = [UIColor blackColor]; backgroundView.tag = 9; UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(cancelPressed:)]; [backgroundView addGestureRecognizer:tapGesture]; [clientView addSubview:backgroundView]; [self bringToFront:backgroundView]; datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, self.bounds.size.height+44, 320, 216)]; datePicker.tag = 10; datePicker.datePickerMode = mode; [clientView addSubview:datePicker]; [clientView bringSubviewToFront:datePicker]; [datePicker becomeFirstResponder]; [self bringToFront:datePicker]; if(date != nil){ datePicker.date = date; } toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.bounds.size.height, 320, 44)]; toolBar.tag = 11; toolBar.barStyle = UIBarStyleBlackTranslucent; UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(donePressed:)]; UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelPressed:)]; [toolBar setItems:[NSArray arrayWithObjects:spacer, doneButton, cancelButton, nil]]; [clientView addSubview:toolBar]; [clientView bringSubviewToFront:toolBar]; [UIView beginAnimations:@"MoveIn" context:nil]; toolBar.frame = toolbarTargetFrame; datePicker.frame = datePickerTargetFrame; backgroundView.alpha = 0.5; [UIView commitAnimations]; }
- clientView is a UIScrollView .
- backgroundView is an auxiliary view described earlier.
This is how I add buttons.
I have only divided part of the button rendering code, because no unnecessary code is needed, and it also has many other dependencies.
-(RenderedElement*)renderElement:(NSObject*)element:(ParentView*)parent:(PageView*)page:(Page*)modelPage:(RenderedElement*)parentRenderedElement { UIButton *buttonView = nil; Button *templateElement = nil; buttonView = [UIButton buttonWithType:UIButtonTypeCustom]; [buttonView setLineBreakMode:UILineBreakModeWordWrap]; [buttonView addTarget:parent action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside]; [parent addSubview:buttonView]; }
UPDATE
When I change the rendering order, and if I press the buttons first, the jump effect does not occur. The user interface is working fine. This temporarily solves the problem. But I want to find a reason and have a better solution.
source share