使用 UITouch 检测特定对象

发布于 2024-09-18 07:30:26 字数 698 浏览 2 评论 0原文

你好 。我正在尝试使用 UITouch 移动 UIImageView 对象,但代码有问题,如何实现 UITouch 来仅检测我的 UIImageView 对象?

**imageA 它是我的 UIImageView

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

        UITouch *toucheA = [[event allTouches] anyObject];

    if ([toucheA view] == imageA) {
        CGPoint location = [toucheA locationInView:self];
        imageA.center = location;       

    }
}

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

    [self touchesBegan:touches withEvent:event];
    CGPoint postion = imageA.center;
    imageA.center = postion;
    postion.y = 230;
    imageA.center = postion;

}

但不起作用!

HI . i am trying to move an UIImageView object with UITouch and have problem with the code how can i implement UITouch to detect only my UIImageView object ?

**imageA it my UIImageView

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

        UITouch *toucheA = [[event allTouches] anyObject];

    if ([toucheA view] == imageA) {
        CGPoint location = [toucheA locationInView:self];
        imageA.center = location;       

    }
}

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

    [self touchesBegan:touches withEvent:event];
    CGPoint postion = imageA.center;
    imageA.center = postion;
    postion.y = 230;
    imageA.center = postion;

}

but doesn't work !

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

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

发布评论

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

评论(1

热血少△年 2024-09-25 07:30:26

我认为您可以通过子类化来创建自定义 UIImageView 并在自定义视图中接收您想要的触摸事件。

一般来说,最上面的视图将接收触摸事件。如果视图处理了触摸事件并且没有将事件传递给另一个视图,那么它后面的其他视图就不可能接收到任何触摸事件。如果视图无法处理触摸事件,它将通过调用 super 的方法来传递该事件。

I think you can make a custom UIImageView by subclassing and receive touch event you want inside the custom view.

Generally, the top most view will receiver the touch event. If the view process the touch event and doesn't pass the event to another view, then the others view behind it are impossible to receive any touch event. If the view cannot deal with the touch event, it will pass that by calling super's method.

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