gpt4 book ai didi

ios - 如何在 iPhone 的手势识别器中获取原始附加 View ?

转载 作者:可可西里 更新时间:2023-11-01 03:36:45 27 4
gpt4 key购买 nike

通过以下代码,我在手势识别器中添加了一个按钮:

UILongPressGestureRecognizer *longPress=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(addLongpressGesture:)];
[longPress setDelegate:self];
[BUTTON addGestureRecognizer:longPress];

这是我的 addLongpressGesture 方法:

- (void)addLongpressGesture:(UILongPressGestureRecognizer *)sender {

UIView *view = sender.view;

CGPoint point = [sender locationInView:view.superview];

if (sender.state == UIGestureRecognizerStateBegan){

// GESTURE STATE BEGAN

}
}

通过这段代码 sender.view 我得到了作为 UIView 的附加 View 但是我想要附加的 View (UIButton),我如何获得 UIView作为 UIButton?

最佳答案

改变这个

UIView *view = sender.view;

为此

UIButton *btn = (UIButton*)sender.view;

关于ios - 如何在 iPhone 的手势识别器中获取原始附加 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19535830/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com