我并不真正熟悉objC,并寻找一种解决方案来构建可用“步骤”滑动的滑块。在移动滑块时,数值会增加,如数值+ = 10或数值+ = 100。我怎么做?具有constum步骤的iphone滑块
1
A
回答
1
我修改上面的代码自定义的Cocos2D滑块http://yannickloriot.com/library/ios/cccontrolextension/Classes/CCControlSlider.html
它具有性能 :
@property (nonatomic, readwrite) float value;
@property (nonatomic, readwrite) minimumValue;
@property (nonatomic, readwrite) maximumValue;
@property (nonatomic, readwrite) int steps;
重新计算:
- (void)recalcuateValue
{
float stepValues[self.steps];
stepValues[0] = self.minimumValue;
stepValues[self.steps - 1] = self.maximumValue;
for(int i = 1; i < self.steps; i++){
stepValues[i] = i * (self.maximumValue - self.minimumValue)/(self.steps - 1);
if (self.value < stepValues[i] && self.value > stepValues[i-1]){
self.value = (self.value > (stepValues[i] - stepValues[i-1])/2 + stepValues[i-1])?stepValues[i]:stepValues[i-1];
}
}
}
而且ccTouchesEnded:我添加如果为例步骤设置为0,滑块可以在照常上班(self.steps!= 0)模式
- (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
if ([self isSelected]){
self.value = [self valueForLocation:_thumbSprite.position];
if(self.steps != 0) {
[self recalcuateValue];
[_thumbSprite setPosition:[self locationFromValue:self.value]];
}
}
self.thumbSprite.color = ccWHITE;
self.selected = NO;
}
它调用valueForLocation和locationFromValu Ë方法:
- (float)valueForLocation:(CGPoint)location
{
float percent = location.x/_backgroundSprite.contentSize.width;
return _minimumValue + percent * (_maximumValue - _minimumValue);
}
- (CGPoint)locationFromValue:(float)value{
float percent = self.value/self.maximumValue;
return ccp(percent * _backgroundSprite.contentSize.width, _backgroundSprite.position.y);
}
所以用法的例子。我需要的滑块3层的步骤和每个步骤值0,1和2:
self.Slider = [CCControlSlider sliderWithBackgroundFile:@"sliderTrack.png"
progressFile:@"sliderProgress.png"
thumbFile:@"sliderThumb-hd.png"]; progressFile:@"sliderProgress.png" thumbFile:@"sliderThumb-hd.png"];
self.Slider.minimumValue = 0.0f;
self.Slider.maximumValue = 2.0f;
self.Slider.steps = 3;
self.Slider.value = [[GameSettings sharedSettings] defaultAILevel];
[self.Slider addTarget:self action:@selector(onSliderValueChanged:) forControlEvents:CCControlEventValueChanged];
希望它可以是有用的
1
我创建了离散滑块这样:
#import <UIKit/UIKit.h>
@interface DiscreteSlider : UISlider {
int step;
}
@property (nonatomic) int step;
@end
这是执行:
#import "DiscreteSlider.h"
@implementation DiscreteSlider
@synthesize step;
- (void) recalcuateStep
{
float lValue = self.value;
int lLowerValue = (int) (lValue/self.step);
float lDifference = lValue - (lLowerValue * step);
float lHalfStep = ((float) step)/2;
if(lDifference < lHalfStep) {
} else {
self.value = (float) (lLowerValue + step);
[self sendActionsForControlEvents:UIControlEventValueChanged];
}
}
- (void) touchesMoved:(NSSet *) touches
withEvent:(UIEvent *) event
{
[super touchesMoved:touches withEvent:event];
NSLog(@"DS.touchesMoved(), event: %@", event);
[self recalcuateStep];
}
- (void) endTrackingWithTouch:(UITouch *) touch
withEvent:(UIEvent *) event
{
[super endTrackingWithTouch:touch withEvent:event];
NSLog(@"DS.endTrackingWithTouch(), event: %@", event);
[self recalcuateStep];
}
- (int) step {
return (step ? step : 1);
}
@end
相关问题
- 1. 使滑块步骤具体值
- 2. Jquery UI滑块步骤0.5
- 3. 具有非线性/指数/对数步骤的JQuery UI滑块
- 4. jQuery UI中的不同步骤滑块
- 5. jQuery UI滑块自定义步骤
- 6. jQuery用户界面滑块步骤
- 7. Javascript/HTML 5滑块步骤问题
- 8. 5个步骤顺利jquery Ui滑块
- 9. ASP.NET AJAX滑块跳过步骤
- 10. TensorBoard更改图片滑块步骤
- 11. 输入范围滑块步骤
- 12. 如何根据滑块值动态设置jquerymobile滑块的步骤?
- 13. 滑动滑块同步滑块 - 3
- 14. jQuery Mobile的滑块时的步骤数量很大行为不
- 15. 具有步骤的数学求解器
- 16. 的UIButton与具有多于1步骤
- 17. 创建具有不同的步骤
- 18. 交错上/下步骤的jQuery UI范围滑块
- 19. 精确计算范围滑块的步骤
- 20. 将滑块中的步骤链接到图像
- 21. 逗号分隔的步骤,具有相同的值的多个步骤
- 22. 对于具有一个步骤,golang
- 23. 是否可以使用滑块步骤表单Element Without Slider?
- 24. jQuery步骤滑块输出多个变量(价格)
- 25. jQuery Mobile滑块 - 使输入能够违反步骤
- 26. 如何创建自定义步骤滑块/范围组?
- 27. 如何用4个步骤制作范围滑块?
- 28. 如何向角度材质滑块添加步骤
- 29. 滑块一步WP7
- 30. 有助于解锁iPhone的滑块