![](/img/trans.png)
[英]IOS, setting up Gesture Tap on UILabel thats inside a UIScrollView
[英]Xamarin IOS UILabel Tap Gesture inside UIScrollView not working
我有一个UIScrollView,并且在其中有一个UILabel。 我需要检测UILabel的轻击手势事件。 目前,它不起作用。 我是xamarin IOS的新手,请帮忙。 提前致谢。
这是我的代码
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);
我已经使用以下代码解决了问题。 在代码上有很小的变化,我已经将UILabel直接添加到了UIScrollView而不是innerview了。
UITapGestureRecognizer singleTap = new UITapGestureRecognizer();
singleTap.CancelsTouchesInView = false;
scrollView.AddGestureRecognizer(singleTap);
scrollView.AddSubview(lViewallLabel);
这篇文章对我的解决很有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.