UIImageView *back = [[UIImageViewalloc]initWithFrame:CGRectMake(0,0,kScreenWidth,kScreenHeight)];
back.image= [UIImageimageNamed:@"Default-568h@2x"];
back.userInteractionEnabled= YES;
[self.viewaddSubview:back];
// 父類view中的imageView
imageView = [[UIImageViewalloc]initWithFrame:CGRectMake(100,100,100,100)];
imageView.image= [UIImageimageNamed:@"Default-568h@2x"];
imageView.userInteractionEnabled= YES;
// 父類view中的label
label = [[UILabelalloc]initWithFrame:CGRectMake(100,240,100,100)];
label.text= @"label";
label.backgroundColor= [UIColorgrayColor];
// 此屬性必須打開,不然UITouch捕獲Label
label.userInteractionEnabled= YES;
// 父類view中的button
button = [UIButtonbuttonWithType:UIButtonTypeCustom];
[buttonsetTitle:@"button"forState:UIControlStateNormal];
button.frame= CGRectMake(100,350,100,100);
button.backgroundColor= [UIColorpurpleColor];
[buttonaddTarget:selfaction:@selector(btn)forControlEvents:UIControlEventTouchUpInside];
UITapGestureRecognizer *tap = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(tap:)];
tap.delegate= self;
[back addGestureRecognizer:tap];
[back addSubview:imageView];
[back addSubview:label];
[back addSubview:button];
}
- (void)btn
{
NSLog(@"button");
{
// 取消label和imageview響應手勢
if ([touch.viewisKindOfClass:[UILabelclass]] || touch.view== imageView)
{
return NO;
}
return YES;
}
- (void)tap:(UITapGestureRecognizer*)tap
{
NSLog(@"tap.view = %@",tap.view);
}