我正在尝试实现没有拇指的垂直 slider ,它会对其轨道上的触摸使用react。我已经对 UISlider 进行了子类化,并且在水平 slider 中一切正常,但是当我将 slider 转换为垂直 slider 时,会出现一些带有坐标的奇怪东西。可能有其他方法来实现这个吗?请给我正确的方向,谢谢!
我现在将此代码用于 slider :
@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
最佳答案
制作垂直 slider 很容易 - 只需旋转 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];
关于objective-c - 自定义垂直 UISlider 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7104692/