2011-08-18 79 views
1

我正在尝试实现无拇指的垂直滑块,它会触动它的轨迹。我已经分类UISlider和一切顺利水平滑块,但是当我将滑块转换为垂直时,有奇怪的东西与坐标进行。可能有其他方法来实现这个?请给我正确的方向,谢谢!自定义垂直UISlider问题

我现在使用此代码为滑块:

@implementation MMTouchSlider 

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 

    UITouch *touch = [[event allTouches] anyObject]; 
    CGPoint touchLocation = [touch locationInView:self]; 

    self.value = self.minimumValue + (self.maximumValue - self.minimumValue) * (touchLocation.x/self.frame.size.width); 

    [super touchesBegan:touches withEvent:event]; 
} 

- (CGRect)thumbRectForBounds:(CGRect)bounds trackRect:(CGRect)rect value:(float)value { 

    CGRect thumbRect = [super thumbRectForBounds:bounds trackRect:rect value:value]; 
    return thumbRect; 
} 

@end 
+1

实际问题是什么?你也可以提供截图吗? – jtbandes

+0

提供屏幕截图并不容易,因为这是触摸故障。滑块值不是我在轨道上点击的位置,就像那样。 –

+0

您能否提供预期的触摸坐标和报告的实际触摸坐标?也许他们可能会含有一些关于开发的线索。 –

回答

0

这很容易使一个垂直滑块 - 只使用270度旋转!

UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(100, 100, 200, 10)]; 
float angleInDegrees = 270; 
float angleInRadians = angleInDegrees * (M_PI/180); 
slider.transform = CGAffineTransformMakeRotation(angleInRadians); 
[self.view addSubView:slider]; 
+0

谢谢,我知道,我在viewDidLoad中使用此代码使其垂直。可能是我应该更清楚的发生奇怪的事情。当滑块是垂直的时候,我点击轨道,滑块的值不在我点击的位置。当它是水平的时候,一切都很好。 –