Ios UIView动画导致UIView按钮跳转
UI是在我的应用程序中以编程方式生成的。我在UI中有几个Ios UIView动画导致UIView按钮跳转,ios,iphone,objective-c,Ios,Iphone,Objective C,UI是在我的应用程序中以编程方式生成的。我在UI中有几个按钮和文本框。我开发了一个自定义的uidatapicker对象,它从屏幕顶部弹出,并在屏幕中间设置动画。当弹出uidatapicker时,我会绘制另一个具有屏幕大小的UIView(称为helper view),以便屏幕中除uidatepicker之外的所有其他uiobject都被禁用。 但是当UIDatePicker正在为UI中的按钮设置动画时,它会跳到另一个位置。我的UI中还有三个按钮。只有一个按钮(UIView中的一个UIButon)会
按钮
和文本框
。我开发了一个自定义的uidatapicker
对象,它从屏幕顶部弹出,并在屏幕中间设置动画。当弹出uidatapicker
时,我会绘制另一个具有屏幕大小的UIView
(称为helper view),以便屏幕中除uidatepicker
之外的所有其他uiobject
都被禁用。
但是当UIDatePicker
正在为UI中的按钮设置动画时,它会跳到另一个位置。我的UI中还有三个按钮。只有一个按钮(UIView中的一个UIButon)会发生这种情况。其他两个按钮可以。除按钮文本外,这些按钮之间也没有显著差异
- 我删除了前面描述的视图(helper视图),但仍然是 问题正在发生
- 我需要知道为什么会发生这种情况 阻止它
- 另外,我还有很多其他的页面,效果很好
-(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
是一个UIScrollView
-
backgroundView
是前面描述的助手视图。这就是我添加按钮的方式
我将只放置按钮呈现代码的一部分,因为放置所有代码是不必要的,并且它还有许多其他依赖项。
-(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];
}
更新
当我更改渲染顺序时,如果我首先渲染按钮,则不会发生跳跃效果。UI工作正常。它暂时解决了这个问题。但是我想找出原因并找到更好的解决方案。也许您可以添加
[UIView setAnimationBeginsFromCurrentState:YES];
之后
你说哪个按钮在动吗?如果没有更多的细节就很难帮上忙。但以下是一些建议: 与其将日期选择器添加到堆栈底部,然后将其向前拉,不如:
[clientView addSubview:datePicker];
[clientView bringSubviewToFront:datePicker];
为什么不尝试通过以下方式添加它:
[clientView insertSubview:datePicker atIndex:0];
另外,在添加datPicker并将其向前拉后,您正在添加工具栏,我认为它包含了有问题的按钮。是否希望工具栏位于视图层次结构中日期选择器的上方
请将其插入:
[clientView insertSubview:toolBar aboveSubview:datePicker];
最后,您需要为工具栏框架设置动画吗?我唯一能想象的是,您可能在客户端视图上有这个按钮。既然你在添加和移动这个
[clientView addSubview:datePicker];
[clientView bringSubviewToFront:datePicker];
这可能会导致重新调整UIButton的框架。因为在这个过程中会发生这种情况,所以它也会对它的运动进行动画处理,可能会显示为一个跳跃按钮。所以我想你应该试试
[jumpingButton setAnimationsEnabled:NO]; //you-know jumping button is the outlet of the -you-know-who
你是在使用自动布局还是结构和弹簧?不,我不是。用户界面也是以编程方式生成的。你能显示一些代码吗?添加了一些代码。你提到的按钮是UIBarButtonim?编辑:虽然我认为这不是。。。你能提供这些按钮的代码吗?我试过你的建议。但它没有起作用。UIView中呈现的UIButton正在移动。是的,工具栏框架也在制作动画。@deltaaruna希望这有帮助!
[jumpingButton setAnimationsEnabled:NO]; //you-know jumping button is the outlet of the -you-know-who