使用 UIView 数组检测 UIScrollView 层中 UIView 的触摸
请原谅我,我对此还很陌生。
我正在尝试检测类似于 MoveMe 示例的触摸 - 只是我将 UIViews (studentCell) 数组放入名为 StudentCellArray 的 NSMutableArray 中。
[self.studentCellArray addObject:self.studentCell];
当我进行一次触摸时,我想让程序足够智能,知道它是否触摸了数组中的任何 UIView,以及是否需要执行某些操作。
这是 TouchBegan: 方法中的代码。
//prep for tap
int ct = [[touches anyObject] tapCount];
NSLog(@"touchesBegan for ClassRoomViewController tap[%i]", ct);
if (ct == 1) {
CGPoint point = [touch locationInView:[touch view]];
for (UIView *studentCard in self.studentCellArray) {
//if I Touch a Card then I grow card...
}
NSLog(@"I am here[%@]", NSStringFromCGPoint(point));
}
我不知道如何访问并触摸它们。
Forgive me I am kinda new at this.
I am trying to detect a touch like the MoveMe example -- only I have an array of UIViews (studentCell) put in to a NSMutableArray called studentCellArray.
[self.studentCellArray addObject:self.studentCell];
When I have one touch I want to make the program smart enough to know if it has touched any of the UIViews in the array and if it has then to do something.
Here is the code in touchesBegan: method.
//prep for tap
int ct = [[touches anyObject] tapCount];
NSLog(@"touchesBegan for ClassRoomViewController tap[%i]", ct);
if (ct == 1) {
CGPoint point = [touch locationInView:[touch view]];
for (UIView *studentCard in self.studentCellArray) {
//if I Touch a Card then I grow card...
}
NSLog(@"I am here[%@]", NSStringFromCGPoint(point));
}
I don't know how t access the views and touch them.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过为数组中的每个 UIView 分配一个 UIPanGestureRecognizer“解决”了这个问题。
这可能不是最好的方法,但我现在可以在屏幕上移动它们。
这是代码:
这是我使用的“拖动”方法。我已将屏幕分为三部分,并且如果 UIView 碰巧跨越阈值,则会有一个动画将其捕捉到一个点。我希望这能给某人一些好主意。如果您能找到更好的方法来执行此操作,请提供帮助。
编辑
:将 [studentCellArray indexOfObjectIdenticalTo:p.view] 添加到 andControlTag 为我提供了所触摸的视图数组中的位置,以便我可以将其传递到我的模式对话框上以呈现适当的信息。
I "solved" this issue by assigning a UIPanGestureRecognizer to each UIView in the array.
This propbably isn't the best way to do it but I can now move them on screen.
Here is the code:
Here is the "dragging" method I used. I have divided the screen into thirds and there is an animation to snap the UIViews to a point if it happens to cross a threshold. I hope this gives someone some good ideas. Please help if you can see any better way to do this.
}
EDIT: Adding [studentCellArray indexOfObjectIdenticalTo:p.view] to the andControlTag gives me the position in the array of the view touched so i can pass that on the my modal dialog to present the appropriate information.