在 iPhone SDK 中将 UIButton 从 UIScrollView 移动到 UIView

发布于 2024-10-31 16:41:27 字数 304 浏览 0 评论 0原文

我遇到了一个问题,实际上场景在我的视图控制器中是这样的,我放置了几个按钮,我可以在视图中移动它们,现在在同一个视图中,一半的屏幕被这个滚动视图中的 uiscrollview 占据,我也有几个 uibuttons,我想要从 uiscrollview 移动到 uiview 现在,当我尝试将 uibutton 从 uiscrollview 移动到 uiview 时,它会在从滚动视图移动时隐藏,就像我将 uibutton 从 uiview 移动到 uiscrollview 一样,然后当我的拖动到达滚动视图区域时它也会隐藏。

请帮我解决这个问题

提前谢谢......

I am stuck with a problem actually the scene is like this in my view controller i have place several buttons which i can move within the view now in same view half of the screens is occupied by uiscrollview in this scrollview also i have several uibuttons which i want to move from uiscrollview to uiview Now when i try to move uibutton from uiscrollview to uiview it hides as it moves from the scrollview similarly as i move uibutton from uiview to uiscrollview then also it hides as my drag reaches the scrollview area.

Please help me out with this problem

Thanks in advance....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心安伴我暖 2024-11-07 16:41:27

每个 UIButton 都有一个超级视图。对于滚动视图中的 UIButtons,UIScrollView 是超级视图。当你有scrollView.clipsToBounds == YES时,如果你将滚动视图中的UIButtons移到滚动视图的可见区域之外,它们将变得模糊。

有几种可能的解决方案,包括:

  1. 添加代码以在 UIButtons 到达滚动视图边缘时更改其超级视图(但这很棘手,除非有更简单的选项,否则我不会这样做,请查看 Apple 的 UIView 文档,特别是 (UIView)removeFromSuperview和(UIView)addSubview:)。您必须在移动按钮(或跟踪移动)的代码中执行超级视图的切换。
  2. 将 UIButtons 添加到 UIView 中,该 UIView 是滚动视图的父级,甚至可能是您的 viewcontroller.view (但滚动视图中的 UIButtons 在滚动时将不再随滚动视图移动)。您可以将按钮添加到滚动视图后面的视图,但使它们显示在滚动视图上方

Your UIButtons each have a superview. For the UIButtons in the scrollview, the UIScrollView is the superview. When you have scrollView.clipsToBounds == YES, then the UIButtons in the scrollview will become obscured if you move them outside of the visible area of the scrollview.

There are several possible solutions, including:

  1. Add code to change the superview of the UIButtons once they reach the edge of the scrollview (but this is tricky, and I wouldn't do it unless there was an easier option, check out Apple's UIView documentation, especially (UIView)removeFromSuperview and (UIView)addSubview:). You would have to perform this switch of superview in the code that moves the button (or tracks the move).
  2. Add the UIButtons to a UIView which is the parent of the scrollview, maybe even your viewcontroller.view (but your UIButtons in the scrollview will no longer move with the scrollview upon scrolling). You would add the buttons to the view behind the scrollview, but so that they show above it.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文