自定义垂直 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
I'm trying to implement vertical slider with no thumb, that reacts to touches on it's track. I have subclassed UISlider and everything goes fine in horizontal slider, but when I'm transforming slider to vertical there is wierd stuff with coordinates going on. May be there is other way to implement this? Please, give me right direction, thanks!
I'm using this code for slider now:
@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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
制作垂直滑块很容易 - 只需使用 270 度旋转即可!
It's easy to make a vertical slider - just use 270 degree rotation!