gpt4 book ai didi

ios - UIViewController 未收到 touchesBegan 消息

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:15:28 25 4
gpt4 key购买 nike

我的 UIViewController 中有一个 UIScrollView。我需要检测对它的任何触摸,然后做一些事情。我还需要什么?

- (BOOL)canBecomeFirstResponder {
return YES;
}

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self becomeFirstResponder];
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"TOUCHED"); // never happens
for (UITouch *touch in touches) {
if ( [touch view] == self.myScrollView)
{
//do something
}
}
}

最佳答案

两种选择:

  1. 子类化 UIScrollView 并实现您的 touchesBegan[...] 代码那里
  2. 将 UIView 添加到您的 UIScrollView 并使用 UIView 的 touchesBegan[...] 委托(delegate)方法

关于ios - UIViewController 未收到 touchesBegan 消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10793809/

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