ios - Xamarin IOS UILabel在UIScrollView中点击手势不起作用
<p><p>我有一个 UIScrollView,里面有一个 UILabel。我需要检测 UILabel 的点击手势事件。目前,它不起作用。我是 xamarin IOS 的新手,请帮忙。提前致谢。</p>
<p><strong>这是我的代码</strong></p>
<pre><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);
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我已经使用下面的代码解决了这个问题。代码的小改动,我已经将UILabel直接添加到UIScrollView而不是innerview。</p>
<pre><code>UITapGestureRecognizer singleTap = new UITapGestureRecognizer();
singleTap.CancelsTouchesInView = false;
scrollView.AddGestureRecognizer(singleTap);
scrollView.AddSubview(lViewallLabel);
</code></pre>
<p>这个 <a href="https://stackoverflow.com/questions/16882737/scrollview-gesture-recognizer-eating-all-touch-events" rel="noreferrer noopener nofollow">post</a>帮我解决了很多问题。</p></p>
<p style="font-size: 20px;">关于ios - Xamarin IOS UILabel在UIScrollView中点击手势不起作用,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/39150123/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/39150123/
</a>
</p>
页:
[1]