gpt4 book ai didi

iphone - 如何在按下按钮后以动画方式显示 UIPickerView?

转载 作者:行者123 更新时间:2023-12-03 18:37:43 24 4
gpt4 key购买 nike

我想在按下按钮后为 UIPickerView 制作动画。我已经将 UIPickerView 编码为隐藏在 viewDidLoad 上,并且在按下按钮后不会隐藏,但它的动画效果不像 ModalViewController 默认情况下的动画效果。我只想让 UIPickerView 具有动画效果,就像默认情况下 ModalViewController 的动画效果一样。

我已经在网站和网络上进行了研究,但我似乎无法正确执行。

这是我的代码:

#pragma mark - Picker View 

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return 4;
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
timersArray = [[NSMutableArray alloc] init];
[timersArray addObject:@"No timer"];
[timersArray addObject:@"15 seconds"];
[timersArray addObject:@"30 seconds"];
[timersArray addObject:@"60 seconds"];

return [timersArray objectAtIndex:row];
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
if ([[timersArray objectAtIndex:row] isEqual:@"No timer"])
{
timerIndication.text = @"No timer selected";
timersPickerView.hidden = YES;
// Animation code to dismiss picker should go here
}
else if ([[timersArray objectAtIndex:row] isEqual:@"15 seconds"])
{
timerIndication.text = @"15 seconds selected";
timersPickerView.hidden = YES;
// Animation code to dismiss picker should go here
}
else if ([[timersArray objectAtIndex:row] isEqual:@"30 seconds"])
{
timerIndication.text = @"30 seconds selected";
timersPickerView.hidden = YES;
// Animation code to dismiss picker should go here
}
else if ([[timersArray objectAtIndex:row] isEqual:@"60 seconds"])
{
timerIndication.text = @"60 seconds selected";
timersPickerView.hidden = YES;
// Animation code to dismiss picker should go here
}
}

#pragma mark - Delay method

// This is where Send button should be enabled
- (IBAction)selectTimer
{
timersPickerView.hidden = NO;
// Animation code to present picker view should go here
}

最佳答案

您可以使用以下代码在按下按钮后为选取器 View 设置动画:

-(IBAction)button:(id)sender
{

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.6];
CGAffineTransform transfrom = CGAffineTransformMakeTranslation(0, 200);
PickerView.transform = transfrom;
PickerView.alpha = PickerView.alpha * (-1) + 1;
[UIView commitAnimations];

}

不要忘记将以下代码添加到您的 viewDidLoad 方法中

PickerView.alpha = 0;    
[self.view addSubview:PickerView];

它的作用是使选择器 View 在第一次单击时从屏幕顶部掉落,并让选择器 View 消失,您只需再次单击该按钮即可。从下一次单击开始,选择器 View 就会出现并消失。 .希望它有帮助并且有效:)

关于iphone - 如何在按下按钮后以动画方式显示 UIPickerView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7924704/

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