2014-01-23 99 views
1

考慮下面的視圖層次最前面的可見UIView沒有收到觸摸,爲什麼?

  • self.view
    • self.transformedView(z變換= 10,索引0)
    • self.ordinaryView(z變換= 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 

看到這個在屏幕上,我只看到了黃色的視圖(變換視圖)。

爲什麼doesen't最前面的可見視圖接受觸摸?

回答

1

在確定哪個視圖應該是觸摸接收器時,UIKit似乎只考慮視圖層次結構。我還沒有找到這方面的文件。

相關問題