您能将UIGestureRecognizer附加到多个视图吗?UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:
self action:@selector(tapTapTap:)];[self.view1 addGestureRecognizer:tapGesture];
[self.view2 addGestureRecognizer:tapGesture];[tapGesture release];在上面的代码中,只点击view2都被认可了。如果我注释掉第三行,然后点击view1都被认可了。如果我是对的,而且您只能使用手势识别器一次,我不确定这是否是一个错误,或者它只是需要更多的文档。
3 回答
ibeautiful
TA贡献1993条经验 获得超6个赞
A UIGestureRecognizerUIGestureRecognizerview
视点
将手势识别器附加到的视图。(只读)
@properties(非原子,只读)UIView*视图
讨论使用addGestureRecognizer:方法向UIView对象附加(或添加)手势识别器。
翻阅古今
TA贡献1780条经验 获得超5个赞
for (UIButton *aButton in myButtons) {
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]
initWithTarget:self action:@selector(handleLongPress:)];
longPress.minimumPressDuration=1.0;
[aButton addGestureRecognizer:longPress];
[longPress release];}- (void)handleLongPress:(UILongPressGestureRecognizer*)gesture {
if ( gesture.state == UIGestureRecognizerStateEnded ) {
UIButton *whichButton=(UIButton *)[gesture view];
selectedButton=(UIButton *)[gesture view];
....}
小唯快跑啊
TA贡献1863条经验 获得超2个赞
func setGestureRecognizer() -> UIPanGestureRecognizer {
var panRecognizer = UIPanGestureRecognizer()
panRecognizer = UIPanGestureRecognizer (target: self, action: #selector(pan(panGesture:)))
panRecognizer.minimumNumberOfTouches = 1
panRecognizer.maximumNumberOfTouches = 1
return panRecognizer }
///set the recognize in multiple views
view1.addGestureRecognizer(setGestureRecognizer())
view2.addGestureRecognizer(setGestureRecognizer())- 3 回答
- 0 关注
- 737 浏览
添加回答
举报
0/150
提交
取消
