更大的 UISlider 可以,但跟踪区域有问题

发布于 2024-08-05 12:43:27 字数 370 浏览 7 评论 0原文

我的目标是创建一个更大的 UISlider,拇指图像高度为 35 像素。

我对 UISlider 进行了子类化并添加了方法:

- (CGRect)trackRectForBounds:(CGRect)bounds
{
    return CGRectMake(bounds.origin.x, bounds.origin.y, self.bounds.size.width, 50);
}

然后我使用 setThumbImage 从控制器设置拇指图像:

我的大拇指得到了很好的显示。

我遇到的问题是跟踪区域在 19 px 高度左右仍然相同,如何将其扩展到 50 ?

谢谢

T。

My goal is to create a bigger UISlider with 35 pixels height for the thumb image.

I subclassed UISlider and added the method :

- (CGRect)trackRectForBounds:(CGRect)bounds
{
    return CGRectMake(bounds.origin.x, bounds.origin.y, self.bounds.size.width, 50);
}

Then I set the thum image from my controller using setThumbImage:

My bigger thumb is well displayed.

The problem I have is that the tracking zone is still the same around 19 px height, how to extend it to 50 ?

Thanks

T.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

葵雨 2024-08-12 12:43:27

iPhone OS 的 UISlider 控件的一个长期存在的问题是你无法将其变得更高。更具体地说,您可以通过为其拇指和轨道指定更高的图像来使其看起来更高,但触摸区域的高度仍为 23 像素。

Michael Patricios 发布了一种方法默认滑块更容易触摸,并且该技术的变体可以处理更大的滑块。您需要做的是子类 UISlider,并覆盖类中的 pointInside:

// How many extra touchable pixels you want above and below the 23px slider
#define SIZE_EXTENSION_Y 10

- (BOOL) pointInside:(CGPoint)point withEvent:(UIEvent*)event {
    CGRect bounds = self.bounds;
    bounds = CGRectInset(bounds, 0, SIZE_EXTENSION_Y);
    return CGRectContainsPoint(bounds, point);
}

在 Interface Builder 中,将滑块设置为使用新的 UISlider 子类,现在您拥有一个可触摸高度为 43px 的滑块。

A long-standing problem with the iPhone OS' UISlider control is that you can't make it taller. More specifically, you can make it look taller by specifying taller images for its thumb and track, but the touch area stays as a tiny 23px tall.

Michael Patricios has published a way to make the default sliders a lot easier to touch, and a variation of that technique can handle larger sliders. What you need to do is subclass UISlider, and override pointInside in your class:

// How many extra touchable pixels you want above and below the 23px slider
#define SIZE_EXTENSION_Y 10

- (BOOL) pointInside:(CGPoint)point withEvent:(UIEvent*)event {
    CGRect bounds = self.bounds;
    bounds = CGRectInset(bounds, 0, SIZE_EXTENSION_Y);
    return CGRectContainsPoint(bounds, point);
}

In Interface Builder, set the slider to use your new UISlider subclass, and you now have a slider with a 43px touchable height.

小情绪 2024-08-12 12:43:27

我正在使用这个解决方案:)

CGRect sliderFrame = self.mySlider.frame;    
sliderFrame.size.height = 142.0; 
[self.mySlider setFrame:sliderFrame];

I'm using this solution :)

CGRect sliderFrame = self.mySlider.frame;    
sliderFrame.size.height = 142.0; 
[self.mySlider setFrame:sliderFrame];
娇纵 2024-08-12 12:43:27

通过增加 UISlider 框架的高度来增加 UISlider 拇指点击区域。这种方法避免了任何偏移以及随后校正滑块框架的需要。

- (void)viewDidLoad{
    [super viewDidLoad];

    //expand slider hit area
    self.slider.frame = CGRectInset(self.slider.frame, 0, -10);

}

Increase UISlider thumb hit area by increasing the height of the UISlider frame. This approach avoids any offset and subsequent need to correct the slider frame.

- (void)viewDidLoad{
    [super viewDidLoad];

    //expand slider hit area
    self.slider.frame = CGRectInset(self.slider.frame, 0, -10);

}
就是爱搞怪 2024-08-12 12:43:27

我相信您可能想看看 thumbRectForBounds:trackRect:value:

I believe that you may want to look at thumbRectForBounds:trackRect:value:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文