UIResponder笔记

  1. UIResponder是什么
    可以响应UIEvent的类,是UIApplication, UIViewUIViewController的父类。它的父类是NSObject
  2. 管理第一响应者。
    • 是否是第一响应者 func isFirstResponder() -> Bool
    • 成为第一响应者 func becomeFirstResponder() -> Bool。只有当前的第一响应者可以放弃成为第一响应者,且这个UIResponder可以成为第一响应者,这个UIResponder才成为第一响应者。 若调用这个函数的是UIView的实例,那么它一定要在视图树(view hierarchy)上。
    • 放弃成为第一响应者 func resignFirstResponder() -> Bool
  3. 管理inputview
    这些方法主要是为了处理输入框或textview成为第一响应者时的键盘。默认情况下,inputview是键盘,inputAccessoryView是键盘上面的view,可以达到键盘上面有输入框跟着键盘一起出现或消失的效果。
    也可以对其他的子类设置自己的inputview。

    - (BOOL)becomeFirstResponder
    {
    [super becomeFirstResponder];
    [self.superview addSubview:self.inputView];
    return YES;
    }
    [button becomeFirstResponder];
    //button的inputview会被加到父view上。
    
  4. 处理touch的事件

    func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?)
    func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?)
    func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?)
    func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?)
    func touchesEstimatedPropertiesUpdated(_ touches: Set<UITouch>)
    
  5. 处理Motion Events
    只提供开始和结束的回调

    func motionBegan(_ motion: UIEventSubtype, with event: UIEvent?)
    func motionEnded(_ motion: UIEventSubtype, with event: UIEvent?)
    func motionCancelled(_ motion: UIEventSubtype, with event: UIEvent?)
    
  6. 处理远程处理事件

    func remoteControlReceived(with event: UIEvent?)
    

更加厉害的分享

posted on 2017-01-14 08:53  花老🐯  阅读(167)  评论(0编辑  收藏  举报

导航