gpt4 book ai didi

iphone - 在 View 中使用 UITapGesture 时不调用 UIButton 操作

转载 作者:搜寻专家 更新时间:2023-10-30 20:10:31 25 4
gpt4 key购买 nike

我有一个 View ,我在那个 View 上添加了一个 UITapGesture。现在,当我在 View 中放置一个按钮并单击该按钮时,它不会调用按钮操作。

这是我的代码:

    ButtionView=[[UIView alloc]initWithFrame:CGRectMake(x, y, 84, 84)];
ButtionView.tag=i;
UIImageView *coverImageView = [[UIImageView alloc]

initWithFrame:CGRectMake(0,0,ButtionView.frame.size.width,84)];
coverImageView.tag = i;
UIButton *notesbutton=[UIButton buttonWithType:UIButtonTypeRoundedRect];
notesbutton.frame=CGRectMake(0, 0,20,20);
notesbutton.tag=i;

[notesbutton addTarget:self action:@selector(buttonClickedForNotes:)
forControlEvents:UIControlEventTouchUpInside];
[ButtionView addSubview:coverImageView];
[ButtionView addSubview:notesbutton];
[notesbutton bringSubviewToFront:ButtionView];
[self.scrollview addSubview:ButtionView];
[ButtionView addGestureRecognizer:oneFingerSingleTap];

-(IBAction)buttonClickedForNotes:(id) sender
{
NSLog(@"buttion action call");

}

最佳答案

首先,订阅 UITapGesture 的委托(delegate)。

[singleTapGestureRecognizer setDelegate:self];

然后你必须让这个按钮成为你所在类(class)的ivar。然后,将此方法添加到您的类中:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
// Check if the touch was on the button. If it was,
// don't have the gesture recognizer intercept the touch
if (CGRectContainsPoint(notesButton.frame, [touch locationInView:self.view]))
return NO;
return YES;
}

希望这对您有所帮助。

关于iphone - 在 View 中使用 UITapGesture 时不调用 UIButton 操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11271959/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com