gpt4 book ai didi

ios - 如何设置 UIView 成为第一响应者?

转载 作者:行者123 更新时间:2023-11-29 01:16:03 26 4
gpt4 key购买 nike

我正在学习 UIResponder。我写了一些测试代码。在我的代码中,我想让 UIView 成为第一响应者,但我失败了。我的测试步骤是:

  1. 在 Storyboard中创建一个 UIView
  2. 为此 View 创建了一个扩展 UIView 的类,并覆盖方法 canBecomeFirstResponder:becomeFirstResponder 以返回 是的

  3. 在 View Controller 的viewDidAppear:方法的方法中,测试一下:

    - (void) viewDidAppear:(BOOL)animated {
    [self.viewD becomeFirstResponder];
    NSLog(@"%d ", [self.viewD isFirstResponder]);
    }

isFirstResponder 的结果总是NO

我不知道为什么。有谁能够帮助我?谢谢。

最佳答案

becomeFirstResponder Notifies the receiver that it is about to become first responder in its window. YES if the receiver accepts first-responder status or NO if it refuses this status. The default implementation returns YES, accepting first responder status.

A responder object only becomes the first responder if the current responder can resign first-responder status (canResignFirstResponder) and the new responder can become first responder.

在您的情况下,您的 View 拒绝状态,这就是为什么它每次都否。

关于ios - 如何设置 UIView 成为第一响应者?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35167862/

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