【发布时间】:2013-05-31 13:04:22
【问题描述】:
我创建了一个UIButton 并将它放在我放在UIScrollView 上的UIImageView 之上。我将按钮添加到图像中,如下所示:
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,但问题是触摸事件也被注册了。
【问题讨论】:
-
此场景中涉及的任何手势识别器?
-
@Stavash 不,没有一个
-
视图层次结构中发生了什么?我看到你在所有其他视图下插入 UIImageView
-
我认为问题在于 AutoResizeSubview 复选框。请取消选中所有 autoresizesubview 复选框。
-
@Stavash 我将自定义 UIView 添加到 UIScrollView。这个视图包含 index:0 处的图像、一个标签和一个 UIButton。这就是它的工作原理
标签: ios cocoa-touch uiview uibutton