- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 UISlider 实现某种形式的捕捉或步骤。我编写了以下代码,但它并没有像我希望的那样顺利。它可以工作,但是当我向上滑动它时,它会向右移动 5 个点,使手指不在“滑动圆”的中心
这是我的代码,其中 self.lastQuestionSliderValue
是我已将其设置为 slider 初始值的类的属性。
if (self.questionSlider.value > self.lastQuestionSliderValue) {
self.questionSlider.value += 5.0;
} else {
self.questionSlider.value -= 5.0;
}
self.lastQuestionSliderValue = (int)self.questionSlider.value;
最佳答案
这实际上比我最初想象的要容易得多。最初我试图获得拇指矩形属性并进行复杂的数学运算。这是我最终得到的结果:
h 文件:
@property (nonatomic, retain) IBOutlet UISlider* questionSlider;
@property (nonatomic) float lastQuestionStep;
@property (nonatomic) float stepValue;
m 文件:
- (void)viewDidLoad {
[super viewDidLoad];
// Set the step to whatever you want. Make sure the step value makes sense
// when compared to the min/max values for the slider. You could take this
// example a step further and instead use a variable for the number of
// steps you wanted.
self.stepValue = 25.0f;
// Set the initial value to prevent any weird inconsistencies.
self.lastQuestionStep = (self.questionSlider.value) / self.stepValue;
}
// This is the "valueChanged" method for the UISlider. Hook this up in
// Interface Builder.
-(IBAction)valueChanged:(id)sender {
// This determines which "step" the slider should be on. Here we're taking
// the current position of the slider and dividing by the `self.stepValue`
// to determine approximately which step we are on. Then we round to get to
// find which step we are closest to.
float newStep = roundf((questionSlider.value) / self.stepValue);
// Convert "steps" back to the context of the sliders values.
self.questionSlider.value = newStep * self.stepValue;
}
确保您连接了 UISlider View 的方法和 socket ,然后就可以开始了。
关于iphone - 实现步骤/捕捉 UISlider,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6370342/
我正在为 tvOS 扩展一个 iOS 应用程序。 在 iOS 应用程序上,我有很多 slider (用于选择年份范围的两侧 slider ,例如 1950-2010。或从 0.1 到 10.0 的值)
目前我正在对 UISlider 进行子类化,并在 drawRect 中设置默认值。我得到了一个奇怪的结果。 slider 最小图像位于正确位置,但 slider 最大图像左侧有空白。中间的 slide
我正在使用 AvPlayer 并尝试设置一个 slider 以允许删除音频文件。我在选定时遇到了问题。然后它会回到原始位置一秒钟,然后再回到它被拖动到的位置。 你在 Gif 上看不到我的光标,但平滑的
我已经创建了一个类似以下代码的 UISlider: BrightnessSlider = [[UISlider alloc] initWithFrame:CGRectMake(sliderXpoint
我有一个连续的 UI slider 。我在值发生变化时获取该值,并使用它来计算放入文本字段的值。 我将值更改导出链接到执行计算并且工作正常的方法,但我还希望在用户抬起 slider 后触发一个方法
关闭。这个问题需要details or clarity .它目前不接受答案。 想要改进这个问题吗? 通过 editing this post 添加详细信息并澄清问题. 关闭 6 年前。 Improve
我的表格单元格中有slider,这是我的 slider 初始化代码: UISlider* slider = [[UISlider alloc] init]; slider.continuous = N
我正在开发一个游戏,它有一个基于 UISliders 的组件。玩家必须从左向右滑动它们,一次一个,有时一次两个。问题出在双幻灯片上。当同时滑动两个 UISlider 时, slider 会滞后于玩家的
我愿意做这个小部件: 只能选择A-B-C。 知道是否有人已经做了类似的事情吗?如果没有,你会怎么做? 最佳答案 就我个人而言,我会使用标准 UISlider 并向 valueChanged 处理程序添
我需要在我的 iPhone 应用程序中添加 UISlider 控件。这应该看起来像任何 iphone 或 iPod touch 中显示的“滑动解锁” slider 。我不知道如何做到这一点。 在滑动解
我正在使用 UISlider 的 setThumbImage:forState 来自定义 slider 拇指的外观。但这看起来要大得多。我使用的图像大小为 55x55 像素。我必须使用的图像大小应该是
恐怕我在这里遗漏了一些明显的东西,但我在任何地方都找不到答案,我似乎也无法自己弄清楚,所以我会在这里问。 是否可以使 UISlider 比默认的稍小一些,就像 iPhone 上“iPod”应用程序中看
这个问题已经有答案了: How to Change the UISlider to Vertical? (4 个回答) 已关闭 9 年前。 如何制作垂直的 UISlider?我在其中一个应用程序中看到
如何自定义UISlider?(更改样式、背景...) 最佳答案 您可以通过this自定义控件的教程。 要自定义 UISlider,请使用本教程中的这段代码。 UIImage *minImage = [
我尝试找出如何强制 slider 的按钮移动它而不是正常滑动,但保持复选框过滤器仍然以正确的方式工作。 当我设置按钮来移动 slider 时,过滤器无法按应有的方式工作。当我将 slider 代码从:
关于如何在 UISlider 中实现不同的值密度,你有什么巧妙的想法/解决方案吗?我的意思是我们将在 UISlider 的左半边有 20 步,在 UISlider 的右半边有 100 步。这意味着最小
我想做这样的事情。我有一个 UISlider它的最小值应该是0,最大值应该是1000。我想把这个范围分成10个部分。像这样。 0-----100----200----300----400 当用户从 0
我已经为 UISlider 设置了缩略图。当我拖动 slider 时,此图像不会反射(reflect)出来。一旦我完成拖动,它就会出现。 我已经为所有状态设置了图像 [self.myslide
我正在构建一个 iOS 应用程序,我必须在其中实现自定义 UISlider。问题是内置的 UISlider 不支持渐变轨道。另一个问题是我的 UI 风格指南显示当前跟踪值矩形应该是两种颜色的渐变,如图
我正在创建(或尝试)自定义 UISlider 外观,仍然是水平的,但要高得多。我有两个问题。 1.这是我用来将图像放到 slider 上的代码。 UIImage *minImage = [UIImag
我是一名优秀的程序员,十分优秀!