简体   繁体   English

在iPhone SDK中将UIButton从UIScrollView移至UIView

[英]Moving UIButton from UIScrollView to UIView in iPhone SDK

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

Please help me out with this problem 请帮我解决这个问题

Thanks in advance.... 提前致谢....

Your UIButtons each have a superview. 每个UIButton都有一个超级视图。 For the UIButtons in the scrollview, the UIScrollView is the superview. 对于滚动视图中的UIButton,UIScrollView是超级视图。 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. 当您具有scrollView.clipsToBounds == YES时,如果将滚动条中的UIButton移到滚动视图的可见区域之外,则它们将变得模糊。

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:). 添加代码以在UIButton到达滚动视图的边缘时更改其超级视图(但这很棘手,除非有更简单的选择,否则我不会这样做,请查看Apple的UIView文档 ,尤其是(UIView)removeFromSuperview和( UIView)addSubview :)。 You would have to perform this switch of superview in the code that moves the button (or tracks the move). 您将必须在移动按钮(或跟踪移动)的代码中执行此Superview切换。
  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). 将UIButtons添加到作为滚动视图父级的UIView中,甚至可以添加到viewcontroller.view中(但滚动时,滚动视图中的UIButton将不再随滚动视图一起移动)。 You would add the buttons to the view behind the scrollview, but so that they show above it. 您可以将按钮添加到滚动视图后面的视图中,但是要在按钮上方显示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM