6

UI 是在我的应用程序中以编程方式生成的。我在 UIbuttons中很少。texboxes我开发了一个自定义uidatapicker对象,它从顶部弹出并动画到屏幕中间。当uidatapicker弹出时,我UIView用屏幕大小绘制另一个(称为辅助视图),因此屏幕uiobject中的所有其他 s 都uidatepicker被禁用。但是,当UIDatePickerUI 中的按钮设置动画时,它会跳转到另一个位置。我的 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];
}


更新
当我更改渲染顺序并且首先渲染按钮时,不会发生跳跃效果。用户界面工作正常。它暂时解决了问题。但我想找到原因并有更好的解决方案。

4

3 回答 3

2

你真的说哪个按钮在移动吗?如果没有更多细节,很难提供帮助。但这里有一些建议可供参考:

而不是将日期选择器添加到堆栈的底部,然后将其向前拉:

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

您为什么不尝试通过以下方式添加它:

[clientView insertSubview:datePicker atIndex:0];

此外,在添加 datPicker 然后将其向前拉之后,您正在添加工具栏,我假设它包含有问题的按钮。您是否希望工具栏位于视图层次结构中的日期选择器上方?

也许将其插入:

[clientView insertSubview:toolBar aboveSubview:datePicker];

最后,您需要为工具栏框架设置动画吗?

于 2013-10-31T13:33:44.223 回答
2

也许你可以添加

[UIView setAnimationBeginsFromCurrentState:YES];

[UIView beginAnimations:@"MoveIn" context:nil];
于 2013-10-24T12:03:44.117 回答
0

我唯一能想象的是,您可能在客户端视图上有这个按钮。并且由于您正在添加和移动它

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

这可能会导致重新调整 UIButton 的框架。并且由于在此过程中发生这种情况,它还会对其运动进行动画处理,这可能会显示为一个跳跃按钮..所以我想你应该试试

[jumpingButton setAnimationsEnabled:NO];  //you-know jumping button is the outlet of the -you-know-who
于 2013-11-07T10:40:51.777 回答