您能將UIGestureRecognizer附加到多個視圖嗎?UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:
self action:@selector(tapTapTap:)];[self.view1 addGestureRecognizer:tapGesture];
[self.view2 addGestureRecognizer:tapGesture];[tapGesture release];在上面的代碼中,只點擊view2都被認可了。如果我注釋掉第三行,然后點擊view1都被認可了。如果我是對的,而且您只能使用手勢識別器一次,我不確定這是否是一個錯誤,或者它只是需要更多的文檔。
3 回答

撒科打諢
TA貢獻1934條經驗 獲得超2個贊
A UIGestureRecognizer
UIGestureRecognizer
view
視點
將手勢識別器附加到的視圖。(只讀)
@properties(非原子,只讀)UIView*視圖
討論使用addGestureRecognizer:方法向UIView對象附加(或添加)手勢識別器。

UYOU
TA貢獻1878條經驗 獲得超4個贊
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貢獻1865條經驗 獲得超7個贊
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 關注
- 745 瀏覽
添加回答
舉報
0/150
提交
取消