gpt4 book ai didi

objective-c - ScrollView 和信息按钮

转载 作者:行者123 更新时间:2023-11-29 04:45:52 24 4
gpt4 key购买 nike

我有自定义的 UIViewController,如下所示。

@implementation UIViewControllerCustom


- (id)init
{
self = [super init];
if (self) {
NSLog(@"init");
}

return self;
}



-(void)viewDidLoad
{
[super viewDidLoad];
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
[infoButton setFrame:CGRectMake(290, 10, 16, 16)];
[infoButton addTarget:self action:@selector(showInfo) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:infoButton];
}

-(void)showInfo
{
About *about = [[About alloc]init];
NSLog(@"touched");
[about setModalTransitionStyle:UIModalPresentationFullScreen];
[self presentModalViewController:about animated:YES];
}

@end

我的应用程序中的任何 View Controller 都会继承此 Controller 。当触摸信息按钮时,会出现模式窗口。问题是我的 View Controller 之一使用 UIScrollView。在这个 Controller 中,信息按钮是可见的,并且它会对触摸使用react。问题是,当我触摸按钮时,未调用 UIViewControllerCustom 的 showInfo 方法。我在其他 Controller 上没有这样的问题。这里可能出了什么问题?

最佳答案

因为 UIScrollView 处理正在发送的消息。在您的情况下,按钮上的触摸将由 UIScrollView 处理。

我建议您对 UIScrollView 进行子类化并实现:- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view 来确定是否UIScrollView 是否应该处理该事件。

实现可能是这样的:

- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view {
if ([view isKindOfClass:[UIButton class]]) {
return NO;
}

return YES;
}

关于objective-c - ScrollView 和信息按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9645866/

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