UISegmentedControl行为 [英] UISegmentedControl Behaviour

查看:94
本文介绍了UISegmentedControl行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于iPhone上的UISegmentedControl类的快速问题。



希望有些人可能已经注意到如何在默认状态下使用2段,分段控件仍会切换即使用户点击当前选中的片段。



我在应用中看到UISegmentedControls否定该行为,并且当用户按下所选内容时不切换分割。即,Apple的iTune Store应用程序。



是否有一种简单的方法可以防止我忽视这种行为,或者我是否需要在valueChanged中写入一些逻辑? / p>

我一直在尝试禁用当前选定的段并启用未选择的段,但这似乎会在我不希望它时改变控件的外观。



任何想法?

解决方案

查看 UISegmentedControl.h 头文件(一种简单的方法是在XCode中双击UISegmentedControl并按住Command)。



在那里你会看到一些 _segmentedControlFlags 结构中的项目。如果你在UISegmentedControl上创建一个类别,你可以操纵任何这些元素 - 包括 dontAlwaysToggleForTwoSegments ,正如你可能猜到的那样,你正在寻找它。



由于这是在API标题中记录的(虽然不在实际文档中),因此使用它应该是非常安全的。


A quick question about the UISegmentedControl class on the iPhone.

Hopefully, some may have noticed how in its default state with 2 segments, the segmented control still will toggle even if the user taps on a segment that is currently selected.

I've seen UISegmentedControls in apps that negate that behaviour and don't toggle when the user presses a selected segment. Namely, Apple's iTune Store app.

Is there a simple way of preventing this behaviour that I'm overlooking, or do I need to write some logic into the valueChanged?

I've been trying to disable currently selected segments and enabling unselected ones, but this seems to change the appearance of the control when I don't want it do.

Any ideas?

解决方案

Look in the UISegmentedControl.h header file (an easy way is to double click on "UISegmentedControl" in XCode with Command held down).

In there you'll see a number of items in a _segmentedControlFlags struct. If you make a category on UISegmentedControl, you can manipulate any of those elements - including dontAlwaysToggleForTwoSegments which as you might guess by the name is what you are looking for.

Since this is documented in the API header (though not in the actual documentation) it should be pretty safe to use.

这篇关于UISegmentedControl行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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