gpt4 book ai didi

ios - iOS5上奇怪的UIButton行为

转载 作者:行者123 更新时间:2023-12-01 19:10:30 26 4
gpt4 key购买 nike

我创建一个UIButton并将其放置在放置在UIImageView上的UIScrollView之上。我将按钮添加到图像中,如下所示:

backgroundImage.frame = CGRectMake(0, 0, backgroundImage.frame.size.width, mainTextView.frame.origin.y + mainTextView.frame.size.height + bottomMargin + attachBlockHeight);
[self insertSubview:backgroundImage atIndex:0];

UIButton *tmpButton = [[UIButton alloc] initWithFrame:CGRectMake(0, imgGreyLine.frame.origin.y + imgGreyLine.frame.size.height, backgroundImage.frame.size.width, attachBlockHeight)];
[tmpButton addTarget:self action:@selector(btnAttachClicked) forControlEvents:(UIControlEventTouchUpInside)];
//tmpButton.backgroundColor = [UIColor redColor];
[backgroundImage addSubview:tmpButton];

而且该按钮在 iOS6及以上版本上都很好用-它在那里,它接收触摸事件并执行其操作。

但是,在 iOS5上,我遇到了一个非常奇怪的行为-该按钮的 frame保持完全相同,并且该按钮明显存在于 view上,但是仅当我 滑动用手指向左或向右滑动时它才接收触摸事件。此外,按钮上方附近没有其他 UIViews!

可能是什么原因呢?我对在这里找到错误感到完全困惑。

编辑:事实证明,滑动 UIButton也适用于 iOS6,但事实是触摸事件也已注册。

最佳答案

您需要在UIImageView父级上启用用户交互

例如:

UIImageView *backgroundImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
[backgroundImage setBackgroundColor:[UIColor yellowColor]];
[backgroundImage setUserInteractionEnabled:YES];
[self.view addSubview:backgroundImage];

UIButton *tmpButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0,50,50)];
[tmpButton addTarget:self action:@selector(btnAttachClicked) forControlEvents:(UIControlEventTouchUpInside)];
tmpButton.backgroundColor = [UIColor redColor];
[backgroundImage addSubview:tmpButton];

关于ios - iOS5上奇怪的UIButton行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16857976/

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