It seems like UIKit only respects the view-hierarchy when determining which view should be the receiver of touches. I have yet to find documentation for this.
Frontmost visible UIView is not receiving touch, why?
-
01-10-2022 - |
Pregunta
Consider the following view hierarchy
- self.view
- self.transformedView (z-transform=10, index 0)
- self.ordinaryView (z-transform=0, index 1)
Put to life by this code
@interface AGSTransformedView : UIView
@end
@implementation AGSTransformedView
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"The transformed view is receiving touch");
[super touchesBegan:touches withEvent:event];
}
@end
@interface AGSOrdinaryView : UIView
@end
@implementation AGSOrdinaryView
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"The ordinary view is receiving touch");
[super touchesBegan:touches withEvent:event];
}
@end
@interface AGSViewController ()
@end
@implementation AGSViewController
- (void)viewDidLoad
{
[super viewDidLoad];
AGSTransformedView *transformed = [[AGSTransformedView alloc] initWithFrame:self.view.bounds];
transformed.layer.transform = CATransform3DMakeTranslation(0, 0, 10);
transformed.backgroundColor = [UIColor yellowColor];
[self.view addSubview:transformed];
AGSOrdinaryView *ordinary = [[AGSOrdinaryView alloc] initWithFrame:self.view.bounds];
ordinary.backgroundColor = [UIColor blueColor];
[self.view addSubview:ordinary];
}
@end
When tapping on the screen I'm seeing this in my console
The ordinary view is receiving touch
On screen I'm only seeing the yellow-colored view (the transform view).
Why doesen't the frontmost visible view receive the touches?
Solución
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow