iphone – touchesbegan,touchesmoved,touchesended issue

iphone – touchesbegan,touchesmoved,touchesended issue,第1张

概述由于各种原因,我已将这些方法从UIView子类移动到我的viewcontroller.除了一件事,我终于得到了它.我不仅可以拖动我以编程方式创建的UI Imageviews,而且实际的视图控制器视图也是可拖动的.创造这种非常不受欢迎的效果.我猜这是事实,它触及任何对象,背景本身就是一个对象.我只是不确定如何排除背景.我认为它需要“启用UserInteraction”,但我猜不是吗?我只想让它使UI 由于各种原因,我已将这些方法从UIVIEw子类移动到我的vIEwcontroller.除了一件事,我终于得到了它.我不仅可以拖动我以编程方式创建的UI ImagevIEws,而且实际的视图控制器视图也是可拖动的.创造这种非常不受欢迎的效果.我猜这是事实,它触及任何对象,背景本身就是一个对象.我只是不确定如何排除背景.我认为它需要“启用UserInteraction”,但我猜不是吗?我只想让它使UIImageVIEws可拖动.请原谅我的noobness.我还在学习.

我想要一个名为“letterDictionary”的NSMutableDictionary中我想要“触摸”的所有图像视图.是否可以只触摸适用于字典中的内容?

http://imgur.com/W08dI

- (voID) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {    UItouch *touch = [touches anyObject];    touchPoint = [touch locationInVIEw:self.vIEw];    movingLetter = [touch vIEw];    CGPoint pointInsIDe = [touch locationInVIEw:[touch vIEw]];    if ([movingLetter pointInsIDe:pointInsIDe withEvent:event]) touchedInsIDe = YES;}- (voID)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {    if (touchedInsIDe) {        UItouch *touch = [touches anyObject];        CGPoint newPoint = [touch locationInVIEw:self.vIEw];  // get the new touch location        movingLetter.center = CGPointMake(movingLetter.center.x + newPoint.x - touchPoint.x,movingLetter.center.y + newPoint.y - touchPoint.y);                 touchPoint = newPoint;          }}- (voID)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {    if (touchedInsIDe) {        UItouch *touch = [touches anyObject];        CGPoint newPoint = [touch locationInVIEw:self.vIEw];        movingLetter.center = CGPointMake(movingLetter.center.x + newPoint.x - touchPoint.x,movingLetter.center.y + newPoint.y - touchPoint.y);        if (CGRectIntersectsRect([movingLetter frame],[placeHolder frame]))            {                movingLetter.center = placeHolder.center;            }    }       touchedInsIDe = NO;}- (voID)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {    touchedInsIDe = NO;}
解决方法 你有被触动的观点,

UItouch *touch = [touches anyObject];    touchPoint = [touch locationInVIEw:self.vIEw];    movingLetter = [touch vIEw];

只是测试它是否是你正在寻找的类(例如UIImageVIEw)然后返回

UItouch *touch = [touches anyObject];    if (![[touch vIEw] isKindOfClass:[UIImageVIEw class]])    {       return;    }
总结

以上是内存溢出为你收集整理的iphone – touchesbegan,touchesmoved,touchesended issue全部内容,希望文章能够帮你解决iphone – touchesbegan,touchesmoved,touchesended issue所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1079437.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存