say*_*guh 1 cocoa-touch objective-c
我正在尝试为我的IBOutletCollection UIButtons中的所有8个按钮添加手势识别器.
for (UIButton *stockButton in stockButtonCollection) {
[stockButton addGestureRecognizer:longpressGesture];
}
Run Code Online (Sandbox Code Playgroud)
似乎这应该对我有用......但事实并非如此.
但是,如果我在循环下面添加这个
[[stockButtonCollection objectAtIndex:0] addGestureRecognizer:longpressGesture];
Run Code Online (Sandbox Code Playgroud)
那它有效吗?
谁能解释一下?谢谢!
更新: 嗯,我可以看到它实际上不是枚举问题..如果在循环下面我添加:[[stockButtonCollection objectAtIndex:0] addGestureRecognizer:longpressGesture]; [[stockButtonCollection objectAtIndex:1] addGestureRecognizer:longpressGesture];
手势识别器仅应用于第二个(objectAtIndex:1),并且不适用于第一个.基本上它只适用于我添加它的最后一个.
任何人都可以解释为什么会这样,我怎么做我想做的事情?:) 谢谢
更新2: 好的,这是我的longpressGesture处理程序
- (void)longPressHandler:(UILongPressGestureRecognizer *)gestureRecognizer {
UIButton *myButton = (id)gestureRecognizer.view;
[myButton setEnabled:NO];
}
Run Code Online (Sandbox Code Playgroud)
所以我想这与单个手势识别器被发送或其他东西有关.我不完全理解它,但有人知道如何做我正在尝试的事情吗?如果按住,我希望所有8个按钮都禁用
更新3 啊,忽略了发布我的手势识别器初始化...这里是
UILongPressGestureRecognizer *longpressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressHandler:)];
longpressGesture.minimumPressDuration = 3;
[longpressGesture setDelegate:(id)self];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
492 次 |
| 最近记录: |