5. 터치 이벤트
콘셉트
UIEvent:
하나의 터치 이벤트(첫 손가락부터 화면을 터치하기 시작해서 마지막 손가락이 화면을 떠나기까지)를 나타낸다. 하나의 UIevent는 여러 개의 UItouch 대상으로 구성되어 있고 몇 개의 손가락이 있으면 몇 개의 터치 대상이 있다.
속성:UIEventType
UIEventTypeTouches,//
UIEventTypeMotion,//
UIEventTypeRemoteControl,//
UIEventTypePresses NS_ENUM_AVAILABLE_IOS(9_0),//
속성: 모든 UITOuch의 객체 컬렉션을 나타내는 allTouchs
UITouch
한 손가락의 클릭 이벤트를 나타낸다. 현재 손가락의 클릭 위치, 상태(터치, 이동, 떠나기)를 나타낼 수 있다.
- (CGPoint)locationInView:(nullable UIView *)view;// view
- (CGPoint)previousLocationInView:(nullable UIView *)view// view
UIResponder
iOS에서 해당 이벤트를 수행할 수 있는 객체는 UIresponder 하위 클래스 객체입니다.UIResponder는 사용자가 리셋을 클릭할 수 있는 네 가지 방법(시작, 이동, 끝, 취소)을 제공했는데 그 중에서 프로그램이 강제로 종료되고 전화가 오는 등 의외의 상황이 중단될 때만'취소'이벤트를 호출할 수 있다.
- (void)touchesBegan:(NSSet *)touches withEvent:(nullable UIEvent *)event;
- (void)touchesMoved:(NSSet *)touches withEvent:(nullable UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(nullable UIEvent *)event;
- (void)touchesCancelled:(NSSet *)touches withEvent:(nullable UIEvent *)event;
- (void)touchesEstimatedPropertiesUpdated:(NSSet *)touches NS_AVAILABLE_IOS(9_1);
UIResponder에서 상술한 방법을 다시 써서 리셋 감청을 할 수 있습니다.
여러 개의 보기가 중첩되고 제스처가 서로 충돌할 때 어느 View가 어느 시간을 처리하는지 어떻게 판단합니까?
현재 응답 체인의 생성과 처리가 관련되어 있습니다.
응답 체인
응답 체인은 현재 보기에서 터치 이벤트를 실행하거나 응답할 수 있는 UIresponder로 구성된 트리 구조입니다
- (nullable UIView *)hitTest:(CGPoint)point withEvent:(nullable UIEvent *)event;
해서 어느 뷰가 처리되었는지 판단합니다.//
- (nullable UIView *)hitTest:(CGPoint)point withEvent:(nullable UIEvent *)event {
//
if (!self.hidden && self.alpha > 0.01 && self.isUserInteractionEnabled) {
//
if ([self pointInside: point withEvent:event]) {
UIView *attachedView;
for (int i = self.subviews.count - 1; i >= 0; i--) {
UIView *view = self.subviews[i];
// view hitTest
attachedView = [view hitTest:point withEvent:event];
if (attachedView)
break;
}
if (attachedView) {
return attachedView;
} else {
return self;
}
}
}
returnnil;
}
더 좋은 글http://www.jianshu.com/p/cb0314b72883
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.