Ios 有人知道如何取消此日期选择器/子视图吗

Ios 有人知道如何取消此日期选择器/子视图吗,ios,Ios,这是我用来在按下按钮时显示UIPickerView的方法,我会用什么方法取消它 if (buttonIndex == 4) { int height = 255; //创建新视图 UIView * newView = [[UIView alloc] initWithFrame:CGRectMake(0, 200, 320, height)]; newView.backgroundColor = [UIColor colorWithWhite:1 alpha:1]; //添加工

这是我用来在按下按钮时显示UIPickerView的方法,我会用什么方法取消它

if (buttonIndex == 4) {
    int height = 255;
//创建新视图

UIView * newView = [[UIView alloc] initWithFrame:CGRectMake(0, 200, 320, height)];
    newView.backgroundColor = [UIColor colorWithWhite:1 alpha:1];
//添加工具栏

UIToolbar * toolbar = [[UIToolbar alloc] initWithFrame: CGRectMake(0, 0, 320, 40)];
    toolbar.barStyle = UIBarStyleBlack;
//添加按钮

UIBarButtonItem *infoButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:nil action:@selector(dismissCustom:)];
    toolbar.items = [NSArray arrayWithObjects:infoButtonItem, nil];
//添加日期选择器

UIDatePicker *datePicker = [[UIDatePicker alloc] init];
    datePicker.datePickerMode = UIDatePickerModeDateAndTime ;
    datePicker.hidden = NO;
    datePicker.date = [NSDate date];
    datePicker.frame = CGRectMake(0, 40, 320, 250);
    [datePicker addTarget:self action:nil/*@selector(changeDateInLabel:)*/ forControlEvents:UIControlEventValueChanged];
    [newView addSubview:datePicker];
//添加弹出视图

[newView addSubview:toolbar];
[self.view addSubview:newView];
//在屏幕上设置动画

CGRect temp = newView.frame;
    temp.origin.y = CGRectGetMaxY(self.view.bounds);
    newView.frame = temp;
    [UIView beginAnimations:nil context:nil];
    temp.origin.y -= height;
    newView.frame = temp;
    [UIView commitAnimations];

}

若要删除视图,请执行另一个动画。只需反转帧设置,使其离开屏幕即可。动画完成后,通过调用
[newView removeFromSuperview]
删除“newView”

你应该考虑使用UIVIEW动画的新的块形式。这将使它变得容易得多

还有一件事。如果您有一个自定义视图类,为什么该自定义类不进行所有的自我设置工作


此外,类名以大写字母开头是标准惯例。这使得在查看代码时很容易区分类名和变量名。

谢谢,我将试一试!只是一个问题,什么是较新的块形式?我会记住最后一点。哦,而且我没有设置自定义视图类,因为我只是在测试一些东西。我不小心输入了错误的代码。请看UIView参考文档。查看“使用块设置视图动画”下的方法列表