【问题标题】:Frontmost visible UIView is not receiving touch, why?最前面可见的 UIView 没有收到触摸,为什么?
【发布时间】:2014-01-23 11:03:42
【问题描述】:

考虑以下视图层次结构

  • self.view
    • self.transformedView(z-transform=10,索引 0)
    • self.ordinaryView(z-transform=0,索引 1)

通过这段代码实现

@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

点击屏幕时,我在控制台中看到了这个

The ordinary view is receiving touch

在屏幕上我只看到黄色视图(变换视图)。

为什么最前面的可见视图没有收到触摸?

【问题讨论】:

    标签: ios objective-c uiview uitouch


    【解决方案1】:

    似乎 UIKit 在确定哪个视图应该是触摸的接收者时只尊重视图层次结构。我还没有找到这方面的文档。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-10
      • 1970-01-01
      相关资源
      最近更新 更多