问题描述
通过点击主 UIView 上的简单 UIButton,附加视图(子视图)出现在屏幕中心(以编程方式创建的子视图).在那个子视图上,我有 UIButton 启动 MPMoviePlayer(此代码在创建子视图的方法内部):
By tapping simple UIButton on main UIView, additional View (subview) appears in the center of screen (subview created programmatically). On that subview I have UIButton that launches MPMoviePlayer (this code is inside method that creates subview):
// Create play button
UIButton *playButton = [UIButton buttonWithType:UIButtonTypeCustom];
[playButton addTarget:self
action:@selector(wtf)
forControlEvents:UIControlEventTouchUpInside];
[playButton setTitle:@"" forState:UIControlEventTouchUpInside];
[playButton setImage:[UIImage imageNamed:[self.playButtons objectAtIndex:[sender tag] - 1]] forState:UIControlStateNormal];
playButton.frame = playButtonRect;
playButton.userInteractionEnabled = YES;
这个按钮在同一个方法中作为子视图添加到这个视图中:
This button added as subview to this view inside the same method:
[self.infoView addSubview:playButton];
在 iOS Simulator 6.0 和带有 iOS 6.0 的真实设备中,一切正常,在 Simulator iOS 5.0 和带有 5.0 的设备中,我有一个非常奇怪的行为:只有当我通过这个按钮的区域进行拖动时,按钮才开始工作,当我只需点击按钮 - 它调用方法,当用户点击屏幕上的任何位置时调用,就像我的按钮没有出现在屏幕上(但在视觉上它确实出现了).我的目标是为 5.x 制作这个应用程序,所以我尝试在这个奇怪的问题上找到答案.
In iOS Simulator 6.0 and real device with iOS 6.0 everything works fine, in Simulator iOS 5.0 and device with 5.0 I have a very strange behavior: button start to work only when I made drag by the area of this button, when I just clicked on button - it called method what called when user taps anywhere in the screen, like my button doesn't appear on screen (but visually it does). My goal is to make this app for 5.x, so I try to find answer on this strange issue.
欢迎任何建议!
推荐答案
您是否正在向 infoView 或其任何子视图添加 UITapGestureRecognizer?
Are you adding a UITapGestureRecognizer to infoView or any of it subviews?
如果是这种情况,您的手势识别器正在禁止 UIButton 操作.您可以在 这篇文章一个>
If that is the case, your gesture recognizer is inhibiting the UIButton action. You could use the solution provided by Kevin Ballard or cdasher on this post
您只需将具有 UITapGestureRecognizer 的视图设置为该手势识别器的委托 (UIGestureRecognizerDelegate).然后可以添加如下代码:
You just need to set the view that has the UITapGestureRecognizer as the delegate of that Gesture Recognizer (UIGestureRecognizerDelegate). Then you can add the following code:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
return ! ([touch.view isKindOfClass:[UIControl class]]);
}
您的点按手势识别器应如下所示:
And your Tap Gesture Recognizer should look like this:
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureAction)];
tap.delegate = self;
[self.view addGestureRecognizer:tap];
希望这会有所帮助!
这篇关于UIButton 在 iOS 5.x 中不起作用,在 iOS 6.x 中一切正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)