gpt4 book ai didi

iphone - 移动包含 UIButtons 的 UIView 会使这些按钮停止响应点击

转载 作者:行者123 更新时间:2023-12-03 20:59:31 25 4
gpt4 key购买 nike

我在 .xib 的 UIView 中的 UIScrollView 中有一个 UIView,其中包含多个按钮。如果我将 UIView 从 viewWillAppear 内向下移动几个像素,所有按钮都会停止响应点击。

这是我用来调整 UIScrollView 大小并将按钮向下移动的代码:

    // adjust the view height to accomodate the resized label
scrollView.contentSize = CGSizeMake( 320, 367 + expectedLabelSize.height - originalLabelSize.height );

// Adjust the location of buttons
CGRect buttonsBounds = buttons.bounds;
buttonsBounds.origin.y -= expectedLabelSize.height - originalLabelSize.height; //XX
buttons.bounds = buttonsBounds;

如果我注释掉标记为 XX 的行,按钮就可以正常工作,但当然位于错误的位置。

如果我尝试不同数量的像素(用硬编码值替换 expectedLabelSize.height - OriginalLabelSize.height),我会得到有趣的结果。 10 像素效果很好。 50 像素导致我的顶部按钮工作正常,但底部按钮无法正常工作。 100 像素,两个按钮都失效。 (-50) 像素会导致底部按钮正常工作,但顶部按钮无法正常工作。

知道是什么原因导致了这个问题吗?我是否需要以某种方式通知按钮其父 View 已移动?

最佳答案

问题是我应该使用buttons.frame而不是buttons.bounds。使用框架解决了问题。

关于iphone - 移动包含 UIButtons 的 UIView 会使这些按钮停止响应点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2166565/

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