UIView animation leads to UIButton transition

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.

+6
source share
3 answers

Perhaps you can add

 [UIView setAnimationBeginsFromCurrentState:YES]; 

after

 [UIView beginAnimations:@"MoveIn" context:nil]; 
+2
source

Did you really say which button is moving? It is hard to help without more details. But here are some tips to look out for:

Instead of adding a datepicker to the bottom of the stack and then pulling it forward:

 [clientView addSubview:datePicker]; [clientView bringSubviewToFront:datePicker]; 

Why don't you try adding it:

 [clientView insertSubview:datePicker atIndex:0]; 

In addition, you add a toolbar, which, I believe, contains an insult button, after adding a datPicker and then moving forward. Do you want the toolbar to be above the datepeck in the view hierarchy?

Maybe paste it in:

 [clientView insertSubview:toolBar aboveSubview:datePicker]; 

Finally, do you need to animate the toolbar border?

+2
source

The only thing I can imagine is that you have this button on the client. and as you add and move this

 [clientView addSubview:datePicker]; [clientView bringSubviewToFront:datePicker]; 

this may result in the reconfiguration of your UIButton frame. and since this happens during this procedure, it also enlivens its movement, which may appear as a transition button. So I think you should try

 [jumpingButton setAnimationsEnabled:NO]; //you-know jumping button is the outlet of the -you-know-who 
0
source

Source: https://habr.com/ru/post/956632/


All Articles