UIView 动画后 UIView 中的 UIButton 不起作用 [英] UIButton inside a UIView not working after UIView is animated

查看:57
本文介绍了UIView 动画后 UIView 中的 UIButton 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这个论坛上看到了很多问题,这些问题给出了UIView 中的 UIButton,动画时不起作用"这一主题的答案,但在尝试了类似的答案后

I have seen many questions in this forum which gives answer to this topic "UIButton inside a UIView, when animated doesn't work", but after having tried out the answers like

a) UIViewAnimationOptionAllowUserInteraction to the options
b) subView.setUserInteractionEnabled = YES
c) [button addTarget:self action:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];

他们都没有为我工作:-(

none of them is working for me :-(

这是场景.应用程序处于横向模式,一个名为 menuView 的 UIView 被放置在 x=480,y=0 处.它的高度=200,宽度=150.所以,当我点击右上角的按钮时,会执行以下代码

Here is the scenario. App is in landscape mode and a UIView called menuView is placed at x=480,y=0. Its height=200 and width=150. So, when I tap the button on the top right corner, the following code is executed

- (IBAction)showMenu {
    [menuView setUserInteractionEnabled:YES];
    [optionsButton setUserInteractionEnabled:YES];
    [UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationCurveEaseOut |  UIViewAnimationOptionAllowUserInteraction
                     animations:^{
                         self.view.frame = CGRectOffset(self.view.frame, 0, 200);
                     }
                     completion:NULL];
}

Output?: View 出现了,但是 menuView 里面的 optionsButton 是不可点击的.我连接到一个事件,做了一个 NSLog(@"Options button clicked"),但没有任何反应:-(

Output?: View is appearing, but optionsButton inside the menuView is not clickable. I hooked up to an event, did an NSLog(@"Options button clicked"), but nothing happens :-(

请告诉我我做错了什么?

Please tell me what I am doing wrong?

更新:当我将menuView"子视图放在 self.view 中时,然后在运行并单击 optionsButton 时,我收到 NSLog 消息.只有我指定menuView的origin.x为480及以上才行.

Update: When I place the subview that is "menuView" inside the self.view, then upon running and click the optionsButton, I get the NSLog message. Only if I specify the origin.x of menuView to be 480 and above, it doesn't work.

推荐答案

如果您可以看到 UIButton,则它的 userInteractionEnabled(默认为YES!)已设置,并且它的超级视图在整个层次结构中的 userInteractionEnabled 是 YES - 您应该能够与它进行交互.

If you can see the UIButton, its userInteractionEnabled (YES by default!) is set, and its superview's userInteractionEnabled in the whole hierarchy is YES - you should be able to interact with it.

动画永远不会改变您的userInteractionEnabled 属性!所以你在那里做的事情根本没有必要.如果您尝试在动画期间启用交互 - 这是另一回事,只是传递给动画消息的一个选项.

An animation will never change your userInteractionEnabled property! So what you are doing there is simply unnecessary. If you try to enable interaction during animation - that's a different story and is just an option passed to the animation message.

因此,如果这不是您的问题(并且可能不是),那么我想超级视图的框架之一是裁剪 UIButton

So if that's not your problem (and is probably not), then I guess one of the superview's frame is cropping the UIButton!

现在您看到,如果 UIButton(或任何 UIView)在 UIView 的框架之外,它仍然可以看到,除非在超级视图上设置了 clipsToBounds.

Now you see, if a UIButton (or any UIView) is outside a UIView's frame, it can still be visible, unless clipsToBounds is set on the superview.

那种情况的结果是:你能看到我,但你不能碰我.

And the outcome of that situation is: You can see me, but you can't touch me.

这篇关于UIView 动画后 UIView 中的 UIButton 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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