ScrollView中的UIButton没有接收到触摸

时间:2014-08-26 17:31:10

标签: ios objective-c uiscrollview

我已经在那里看到了一些类似的问题,但是他们都没有对我的问题有一个有效的答案。

我的观点结构是:

[VIEW]
[滚动型]
[第1页] [第2页] [第3页] [第4页]

在第4页我有:

[PAGE 4]
[ImageView的] [按钮]

所有内容都正确显示,但我的按钮没有触及。

我尝试过foruns和教程的一些解决方案,我的ScrollView子类的代码目前就是这个:

TutorialScrollView.m

-(void)didMoveToSuperview{

self.delegate = self;
self.delaysContentTouches = NO;
self.canCancelContentTouches = YES;
self.userInteractionEnabled = YES;
}

-(BOOL)touchesShouldCancelInContentView:(UIView *)view{

return ![view isKindOfClass:[UIButton class]];

}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UIView *hitView = [self hitTest:[(UITouch*)[[touches allObjects] objectAtIndex:0] locationInView:self] withEvent:event];
if ([hitView isKindOfClass:[UIButton class]]) {
    [(UIButton*)hitView sendActionsForControlEvents:UIControlEventTouchUpInside];
}
[super touchesBegan:touches withEvent:event];
}

我注意到方法-touchesShouldCancelInContentView不是仅在第4页中调用,而是在其正常调用的所有其他页面中调用。

提前致谢!

1 个答案:

答案 0 :(得分:0)

你可以将你的uibutton链接到一个ibaction,所以你不需要触摸......

-(IBAction)buttonTouched:(id)sender{

    //do stuff

}
相关问题