如何禁用 UIPickerView (Swift)? [英] How to disable UIPickerView (Swift)?

查看:38
本文介绍了如何禁用 UIPickerView (Swift)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想禁用 UIPickerView,但将其设置为isEnabled = false";不起作用.不,我不想在使用视图时禁用它,而是在执行特定操作以重新启用视图之前无法滚动视图.

I would like to disable the UIPickerView, but setting it to "isEnabled = false" does not work. And no, I don't want to disable the view while using it, but instead not being able to scroll through the view until a certain action is done for it to be re-enabled.

我在这里尝试的代码不起作用(它甚至可能不是 swift 代码):如何禁用 UIPickerView (目标-C)?

The code I tried here doesn't work (it may not even be swift code): How to disable UIPickerView (Objective-C)?

推荐答案

要禁用用户输入,请使用:

To disable user input, use:

myPickerView.isUserInteractionEnabled = false

然后,要重新启用用户输入,请使用:

Then, to re-enable user input, use:

myPickerView.isUserInteractionEnabled = true

来自 .isUserInteractionEnabled 上的 Apple 文档页面:

From the Apple Documentation Page on .isUserInteractionEnabled:

当设置为 false 时,用于视图的用户事件(例如触摸和键盘)将被忽略并从事件队列中删除.当设置为 true 时,事件会正常传递到视图.

When set to false, user events—such as touch and keyboard—intended for the view are ignored and removed from the event queue. When set to true, events are delivered to the view normally.

这篇关于如何禁用 UIPickerView (Swift)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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