屏幕下方以编程方式创建的 UIButton 不起作用? [英] Programmatically Created UIButtons Below Screen Not Working?

查看:25
本文介绍了屏幕下方以编程方式创建的 UIButton 不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个包含一些图像的盒子矩阵.为了管理点击并获取点击了哪个框,我在每个不可见的框内放置了一个 UIButton 以及框的大小.

I am creating a matrix of boxes with some images in them. To manage the taps and get which box was tapped I am placing one UIButton inside of each box that is invisible and also the size of the box.

我像这样添加了事件监听器(抱歉,我是 Javascript 程序员:)):

I added the event listener (sorry, I'm a Javascript programmer :) ) like this:

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

我启动了模拟器,它运行得很好.我可以在日志中看到按钮的标签.然而,然后我向下滚动,令我惊讶的是,屏幕折叠下方的按钮根本没有工作.没有发送事件.我对此完全感到困惑,不知道是什么导致了它.有人有什么想法吗?

I started the simulator up and it worked just fine. I can see the tag of the button in the log. However, I then scrolled down, and to my surprise, NONE of the buttons below the fold of the screen worked at all. No events were being sent. I am completely baffled by this and have no clue what would cause it. Does anyone have any ideas?

基本上,总而言之,屏幕初始底部以下的任何内容都不会触发操作.当一个盒子的一半最初被切断时,只有第一次显示视图时暴露的(顶部)一半有效.下半部分不会触发动作.

Basically, as a summary, anything below the initial bottom of the screen never triggers an action. When half of a box is initially cut off, only the (top) half exposed when the view was first displayed works. The bottom half will not trigger the action.

推荐答案

原因之一是您的按钮实际上位于框的边界之外.这些按钮仍然可见,因为您还没有将框设置为剪切边界外的任何内容.因此这些按钮无法接收任何输入事件.

One of the reasons is your buttons are actually placed outside your boxes' boundary. The buttons are still visible because you haven't set your boxes to clip anything outside the bound. And hence these buttons cannot receive any input event.

您可以尝试为您的框设置 clipsToBounds = YES 并查看按钮是否仍然可见?

You can try to set clipsToBounds = YES for your boxes and see if the buttons are still visible?

这篇关于屏幕下方以编程方式创建的 UIButton 不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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