gpt4 book ai didi

iphone - 隐藏/显示 UIPickerView

转载 作者:行者123 更新时间:2023-12-03 18:19:56 26 4
gpt4 key购买 nike

我有一个 TouchsEnded 事件,用于检查何时按下 UITextField。我希望它做的是隐藏/显示 UIPickerView。如何做到这一点?

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [[event allTouches] anyObject];
if (CGRectContainsPoint([self.textField frame], [touch locationInView:self.view]))
{
NSString * error = @"Touched the TextField";
UIAlertView * errorAlert = [[UIAlertView alloc] initWithTitle:@"Selection!" message:error delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[errorAlert show];
//Want to show or hide UIPickerView
}
}

当触摸发生时,我已经分配了 UIPickerView

@interface ThirdViewController : UIViewController <UITextFieldDelegate,UIPickerViewDelegate> {
IBOutlet UIPickerView *pickerView;
}

最佳答案

切换“隐藏”属性可以达到目的,但也会带来非常突然的显示。

避免这种情况的一种方法是将选择器嵌入 UIActionSheet 中,使其从屏幕底部向上滑动。

这是一个例子:

    UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:nil 
delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];

CGRect pickerFrame = CGRectMake(0, 0, 0, 0);
UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame];
pickerView.showsSelectionIndicator = YES;
pickerView.dataSource = self;
pickerView.delegate = self;
[sheet addSubview:pickerView];
[pickerView release];

[sheet showInView:view];
[sheet setBounds:CGRectMake(0, 0, 320, 415)];
self.actionSheet = sheet; // assuming you have setup a property to hold the action sheet
[sheet release];

使用完选择器后,将其关闭:

[self.actionSheet dismissWithClickedButtonIndex:0 animated:YES];

这种方法也可用于在选择器上方的栏中合并按钮(“完成”、“上一个”、“下一个”等) - 关于如何做到这一点有一个很好的解释 here .

关于iphone - 隐藏/显示 UIPickerView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2634242/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com