移动滑块控件时尝试找出我的触摸位置

发布于 2024-07-29 22:52:30 字数 345 浏览 5 评论 0原文

我想在 iPhone 上创建一个变速滑块控件。 基本上我使用的是 UISlider 控件,但我想通过检测手指在当前视图中的位置来向该控件添加第二个维度。

EG 用户可以左右滑动控件,但我想查看他们的手指在视图中的垂直位置。

我的问题是当您操纵滑块控件时。 不调用以下函数。

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event

所以这意味着我无法检测到任何触摸事件,因为我假设它们被发送到滑块? 有人尝试这样做吗? 或者我应该将 UISlider 子类化。 嗯。

I would like to create a variable speed slider control on the iPhone.
Basically I am using a UISlider control but I would like to add a second dimension to this control by detecting where the finger is in the current view.

E.G. A user can slide the control left and right, but I want to see where their finger is vertically in the view.

My issue is that when you are manipulating a slider control.
The following function is not called.

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event

so this means I cannot detect any touch events because I assume they are being sent to the slider? Anyone tried to do this? Or should I sub class UISlider. Hmmm.

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

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

发布评论

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

评论(1

十年不长 2024-08-05 22:52:31

标头

#import <Foundation/Foundation.h>


@interface JBSlider : UISlider {
    double verticalTouchDelta;
}
@property(nonatomic, assign)    double verticalTouchDelta;

@end

主文件

导入“JBSlider.h”@implementation

JBSlider

@synthesizeverticalTouchDelta;
- (void)sendAction:(SEL)action to:(id)target forEvent:(UIEvent *)event{
[super sendAction:action to:target forEvent:事件];
//NSLog(@"HI HI");

UITouch * touch = [[event touchesForView:self] anyObject];
//NSLog(@"%f", [touch locationInView:self].y);
verticalTouchDelta  = [touch locationInView:self].y;    

@end

只需在 Interface Builder 中将滑块从 UISlider 更改为 JBSlider 即可
效果棒极了。

header

#import <Foundation/Foundation.h>


@interface JBSlider : UISlider {
    double verticalTouchDelta;
}
@property(nonatomic, assign)    double verticalTouchDelta;

@end

main file

import "JBSlider.h"

@implementation JBSlider

@synthesize verticalTouchDelta;
- (void)sendAction:(SEL)action to:(id)target forEvent:(UIEvent *)event{
[super sendAction:action to:target forEvent:event];
//NSLog(@"HI HI");

UITouch * touch = [[event touchesForView:self] anyObject];
//NSLog(@"%f", [touch locationInView:self].y);
verticalTouchDelta  = [touch locationInView:self].y;    

}

@end

Simply change your slider from UISlider to JBSlider in Interface Builder.
Works awesome.

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