将事件从 UIScrollView 转发到 UIButton

发布于 2024-11-07 09:25:20 字数 374 浏览 0 评论 0原文

我在 UIScrollView 内有一个 UIButton 。问题是 UIButton 不够大,无法填充整个 UIScrollView。我希望能够将 UIScrollView 其他区域的触摸事件转发到 UIButton。这是我的应用程序的屏幕截图:

http://imageshack.us/photo/my -images/405/img1410.png/

有谁知道该怎么做?

I got an UIButton inside an UIScrollView. The problem is that the UIButton is not big enough to fill the entire UIScrollView. I'd like to be able to forward the touch events in other areas of the UIScrollView to the UIButton. Here's a screenshot of my app:

http://imageshack.us/photo/my-images/405/img1410.png/

Does anyone knows how to do that?

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

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

发布评论

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

评论(3

谁把谁当真 2024-11-14 09:25:20
[button addTarget:self action:@selector(itemTouched:)forControlEvents:UIControlEventTouchUpInside];

- (void) itemTouched:(UIButton*) sender
{
  [self performSelectorOnMainThread:@selector(doSomething:) withObject:sender waitUntilDone:NO];
}

UIButton 的高亮部分可以在调用 doSomething 方法之前显示。

[button addTarget:self action:@selector(itemTouched:)forControlEvents:UIControlEventTouchUpInside];

- (void) itemTouched:(UIButton*) sender
{
  [self performSelectorOnMainThread:@selector(doSomething:) withObject:sender waitUntilDone:NO];
}

The highlight of UIButton can be shown before call doSomething method.

黯淡〆 2024-11-14 09:25:20

我不确定你可以以这种方式转发触摸,但我想你可以调整 UIButton 的大小以填充整个滚动视图并使内容不拉伸,这样它看起来相同,但会有一个更大的 UIButton。

I'm not sure you can forward touches in that manner, but I guess you could resize the UIButton to fill the whole scrollView and make the content not stretch, such that it looks identical, but there'd be a much bigger UIButton.

著墨染雨君画夕 2024-11-14 09:25:20

要将触摸沿着链传播到子视图,请

[mychild touchesBegan:touches withEvent:event];

在scrollView的touchesBegan中使用:。

To propagate touches down the chain to a sub view use:

[mychild touchesBegan:touches withEvent:event];

in your scrollView's touchesBegan.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文