How to make a button scroll inside a UIScrollView?

依然范特西╮ 提交于 2020-01-25 10:29:05

问题


It's possible to put a button inside a scroll view and make it scroll together with the view?

I try to explain the issue. I have a scrollView containing a textView showing some text. In the text there's a link and i have a button, put beside this link that, when pressed, open the link in safari. Now, the text is longer than the textView, so i had to put the Text view inside a Scroll View to make it scroll. I tried putting the button inside the scrollView as well, but when i scroll, only the text get scrolled and the button stays still where it is, when instead i want the button to scroll together with the text, to have it evere beside the link that is in the text. Is is possible?


回答1:


As far as I'm aware, you can't put controls inside a UITextView.

You could implement your desired behaviour by moving the button during the textView's - (void)scrollViewDidScroll:(UIScrollView *)scrollView delegate method.

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    // Move button according to scroll position, using scrollView.contentOffset
}


来源:https://stackoverflow.com/questions/15270377/how-to-make-a-button-scroll-inside-a-uiscrollview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!