UI 是在我的应用程序中以编程方式生成的。我在 UIbuttons
中很少。texboxes
我开发了一个自定义uidatapicker
对象,它从顶部弹出并动画到屏幕中间。当uidatapicker
弹出时,我UIView
用屏幕大小绘制另一个(称为辅助视图),因此屏幕uiobject
中的所有其他 s 都uidatepicker
被禁用。但是,当UIDatePicker
UI 中的按钮设置动画时,它会跳转到另一个位置。我的 UI 中还有三个按钮。它只发生在一个按钮上(UIView 中的一个 UIButon)。其他两个按钮没问题。除了按钮文本之外,这些按钮之间也没有显着差异。
- 我删除了前面描述的视图(帮助视图),但问题仍然存在。
- 我需要知道为什么会发生这种情况如何防止它。
- 此外,我还有很多其他页面都可以正常工作。
编码
-(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];
}
更新
当我更改渲染顺序并且首先渲染按钮时,不会发生跳跃效果。用户界面工作正常。它暂时解决了问题。但我想找到原因并有更好的解决方案。