简体   繁体   English

Xamarin IOS UILabel UIScrollView内部的手势手势不起作用

[英]Xamarin IOS UILabel Tap Gesture inside UIScrollView not working

I have an UIScrollView and inside this I have an UILabel. 我有一个UIScrollView,并且在其中有一个UILabel。 I need to detect tap gesture events for the UILabel. 我需要检测UILabel的轻击手势事件。 At the moment, it' not working. 目前,它不起作用。 I am new in xamarin IOS, please help. 我是xamarin IOS的​​新手,请帮忙。 Thanks in advance. 提前致谢。

Here is my Code 这是我的代码

UILabel lViewallLabel = new UILabel(new CGRect((View.Bounds.Width / 2) - 20, 270, View.Bounds.Width / 2, 16));
lViewallLabel.Text = "VIEW ALL >>";
lViewallLabel.TextAlignment = UITextAlignment.Right;
lViewallLabel.TextColor = UIColor.White;
lViewallLabel.Font = UIFont.SystemFontOfSize(12f);
lViewallLabel.AdjustsFontSizeToFitWidth = true;
lViewallLabel.UserInteractionEnabled = true;
UITapGestureRecognizer tgrLabel2 = new UITapGestureRecognizer(() =>
       {
             UIAlertView myAlert = new UIAlertView();
             myAlert.AddButton("OK");
             myAlert.Message = "Label was tapped.";
             myAlert.Title = "It worked!";
             myAlert.Show();
        });
lViewallLabel.AddGestureRecognizer(tgrLabel2);
innerView.AddSubview(lViewallLabel);

scrollView.AddSubview(innerView);

I have solve the problem using the below code. 我已经使用以下代码解决了问题。 Small change in code, I have added the UILabel directly to the UIScrollView instead of innerview. 在代码上有很小的变化,我已经将UILabel直接添加到了UIScrollView而不是innerview了。

UITapGestureRecognizer singleTap = new UITapGestureRecognizer();
singleTap.CancelsTouchesInView = false;
scrollView.AddGestureRecognizer(singleTap);

scrollView.AddSubview(lViewallLabel);

This post helped me lot to solve the issue. 这篇文章对我的解决很有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM