第一次单击按钮时未出现Picker View [英] Picker View not appearing on 1st attempt of button click

查看:39
本文介绍了第一次单击按钮时未出现Picker View的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在单元格的最右边有一个按钮.

I have a button on the extreme right of the cell.

现在我有一个选择器视图,需要在单击按钮时显示它.

Now I have a picker view which needs to be displayed on button click.

使用以下代码可以正常工作:

Its working fine with the following code:

-(IBAction)buttonPressed:(id)sender
{
[UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.3];
    CGAffineTransform transform = CGAffineTransformMakeTranslation(0, 200);
    monthPicker.transform = transform;
    [self.view addSubview:monthPicker];
    [UIView commitAnimations];  
}

但是我搜索了使选择器视图可见时隐藏并在不存在选择器视图时显示它,我找到了解决方案.....在以下方法中添加了以下代码:

But I searched for making picker view hide when it is visible and be shown when no picker view is present,I found out a solution for it.....added the following code to above method:

monthPicker.hidden = [monthPicker isHidden]吗?否:是;

monthPicker.hidden = [monthPicker isHidden] ? NO : YES;

现在,当我单击按钮时,选择器视图在第一次尝试时没有显示,但是从第二次尝试开始,它的工作状态就完美了.

Now the picker view is not getting displayed on 1st attempt when I click button,but it's working perfect from 2nd attempt and later.

有什么建议吗?

推荐答案

@Padavan的答案应该起作用,但是如果您希望在动画中"使用淡入淡出效果,则隐藏属性不能起作用.您必须改为使用UIView.alpha属性.这是我的示例代码.

The answer from @Padavan should work, but if you want fading effect "in animation", hidden property does not do the job. You have to use UIView.alpha property instead. Here is my sample code for that.

- (void) viewDidLoad {
       [super viewDidLoad];

       /////////////////////////////////////////////////
       //    ... Initialize your month picker here    //
       /////////////////////////////////////////////////

       monthPicker.alpha = 0;    
       [self.view addSubview:monthPicker];    
}

- (void)buttonPressed:(id)sender
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.3];
    CGAffineTransform transform = CGAffineTransformMakeTranslation(0, 200);
    monthPicker.transform = transform;
    monthPicker.alpha = monthPicker.alpha * (-1) + 1;
    [UIView commitAnimations];  
}

这篇关于第一次单击按钮时未出现Picker View的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆