Я пытаюсь создать подкласс UIView и создать прозрачный вид. Это представление будет располагаться поверх многих других представлений, и его единственная задача — захватывать и записывать прикосновения пользователя (нажатие и панорамирование). Я пробовал много разных методов, объясненных в разных вопросах, заданных другими пользователями, но безуспешно. Это то, что я сделал до сих пор в своем файле реализации:
#import "touchLayer.h"
@implementation touchLayer
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) [self commonInit];
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) [self commonInit];
return self;
}
- (void)commonInit
{
self.userInteractionEnabled = YES;
self.alpha = 0.0;
}
- (id)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
id hitView = [super hitTest:point withEvent:event];
if (hitView == self)
{
UITouch *touch = [[event allTouches] anyObject];
if (touch.phase == UITouchPhaseBegan) NSLog(@"touchesBegan");
else if (touch.phase == UITouchPhaseMoved) NSLog(@"touchesMoved");
else if (touch.phase == UITouchPhaseEnded) NSLog(@"touchesEnded");
return nil;
}
else
return hitView;
}
@end
Теперь этот код работает нормально, и я вижу касания в нижних слоях, но не могу различить touchBegan, touchMoved и touchEnded. [[event allTouches] anyObject]
возвращает ноль. У вас есть идеи, как я могу захватить нажатие и панорамирование на UIView, не блокируя касания? Большое спасибо.
func touchesBegan(touches: NSSet, withEvent event: UIEvent)
,func touchesMoved(touches: NSSet, withEvent event: UIEvent)
иtouchesEnd
- person trungduc   schedule 05.11.2017[super touchesBegan:touches withEvent:event];
, чтобы отправить касание на следующий вид, не повезло. - person Babak Samareh   schedule 05.11.2017