容器视图内的按钮不起作用 [英] Buttons inside container view does not work

查看:16
本文介绍了容器视图内的按钮不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个开发 iOS 应用程序的菜鸟,我现在正在开发一个应用程序.

I am a total noob developing iOS applications and I'm working in one right now.

我已经使用 HomeViewController(主要)设置了我的故事板,其中包含一个容器视图,其中嵌入了另一个视图控制器.这个子视图控制器在视图的边界之外,当点击我的 HomeViewController 中的一个按钮时,它会动画到我的应用程序的顶部,用很酷的动画显示这个孩子.一切正常.

I have set up my storyboard with a HomeViewController (main) and inside this, a container view, with another view controller embeded. This child view controller is outside the bounds of the view, and when a click a button in my HomeViewController it gets animated to the top of my app, showing this child with a cool animation. Everything is right.

在我的子视图控制器中,我只有 3 个按钮,当它们以这个小动画显示在屏幕上时,它们不可用.它们不会触发按下按钮的动作,也不会以 iOS 风格突出显示".什么都没发生.

In my child view controller I only have 3 buttons, and when they are displayed on the screen with this little animation, they are not usable. They don't trigger the action of the button being pressed nor they get "highlighted" with iOS style. Nothing happens.

我对此进行了很多搜索,我在父级上尝试了 addChildViewController(),在子级上尝试了 didMove(toParentViewController: UIViewController) 并且我还以编程方式添加了它.当以编程方式添加时,它工作正常,但视图不尊重动画,只是显示在屏幕中而不遵循父容器,它确实随着动画移动.

I have been searching a lot about this, I have tried addChildViewController() on parent, didMove(toParentViewController: UIViewController) on child and I also have added it programmatically. When added programmatically it works OK but the view does not respect the animation, just being displayed in the screen without following the parent's container, which indeed moves with the animation.

接下来我该怎么办?

非常感谢

我的问题似乎不是 UIView 动画取消任何触摸的重复输入

我使用 Spring 库来制作动画.此外,在该线程中,他们正在谈论在动画未完成时阻止用户交互.那不是我的情况.尝试按钮交互时动画完美完成.

I'm using Spring library for the animations. Also, in that thread they are talking about user interaction being blocked while animation isn't finished. That is not my case. Animation is perfectly finished when trying the button interaction.

推荐答案

根据我的经验,有两个问题最常导致这种行为:

From my experience, there are two issues which cause this behavior most often:

  1. 您的某些容器视图将 userInteractionEnabled 设置为 false,或
  2. 您的容器视图框架很小,您正试图点击容器框架外的按钮,但该按钮不起作用.把它想象成一个按钮的窗口,有一个无形的墙阻止触摸.

最好使用 Xcode Debug View Hierarchy 调试这两种方法,或者您也可以尝试使用 Reveal 应用程序,看看那里发生了什么.

Both of these are best debugged using the Xcode Debug View Hierarchy, or you can also try the Reveal app and see what's going on there.

这篇关于容器视图内的按钮不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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