- UIResponder是什么
可以響應UIEvent的類,是UIApplication
, UIView
及UIViewController
的父類诺祸。它的父類是NSObject
- 管理第一響應者寓盗。
- 是否是第一響應者
func isFirstResponder() -> Bool
- 成為第一響應者
func becomeFirstResponder() -> Bool
。只有當前的第一響應者可以放棄成為第一響應者,且這個UIResponder可以成為第一響應者张症,這個UIResponder才成為第一響應者检疫。
若調(diào)用這個函數(shù)的是UIView
的實例讶请,那么它一定要在視圖樹(view hierarchy)上。
- 放棄成為第一響應者
func resignFirstResponder() -> Bool
- 管理inputview
這些方法主要是為了處理輸入框或textview成為第一響應者時的鍵盤电谣。默認情況下秽梅,inputview
是鍵盤,inputAccessoryView
是鍵盤上面的view剿牺,可以達到鍵盤上面有輸入框跟著鍵盤一起出現(xiàn)或消失的效果企垦。
也可以對其他的子類設置自己的inputview。
- (BOOL)becomeFirstResponder
{
[super becomeFirstResponder];
[self.superview addSubview:self.inputView];
return YES;
}
[button becomeFirstResponder];
//button的inputview會被加到父view上晒来。
- 處理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>)
- 處理Motion Events
只提供開始和結(jié)束的回調(diào)
func motionBegan(_ motion: UIEventSubtype, with event: UIEvent?)
func motionEnded(_ motion: UIEventSubtype, with event: UIEvent?)
func motionCancelled(_ motion: UIEventSubtype, with event: UIEvent?)
- 處理遠程處理事件
func remoteControlReceived(with event: UIEvent?)
更加厲害的分享
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者