如何使按钮在 UIScrollView 内滚动? [英] How to make a button scroll inside a UIScrollView?

查看:22
本文介绍了如何使按钮在 UIScrollView 内滚动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在滚动视图中放置一个按钮并使其与视图一起滚动?

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

我试着解释这个问题.我有一个包含显示一些文本的 textView 的滚动视图.在文本中有一个链接,我有一个按钮,放在这个链接旁边,当按下时,在 safari 中打开链接.现在,文本比 textView 长,所以我不得不将 Text 视图放在 Scroll View 中以使其滚动.我也尝试将按钮放在 scrollView 内,但是当我滚动时,只有文本被滚动,按钮保持原地不动,而我希望按钮与文本一起滚动,让它一直在链接旁边那是在文本中.有可能吗?

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?

推荐答案

据我所知,你不能将控件放在 UITextView 中.

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

您可以通过在 textView 的 - (void)scrollViewDidScroll:(UIScrollView *)scrollView 委托方法.

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
}

这篇关于如何使按钮在 UIScrollView 内滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆