2016-08-25 80 views
2

我有一個UIScrollView,裏面有一個UILabel。我需要檢測UILabel的輕擊手勢事件。目前,它不工作。我是xamarin IOS新手,請幫忙。提前致謝。Xamarin IOS UILabel點擊手勢裏面UIScrollView不工作

這裏是我的代碼

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); 

回答

3

我使用下面的代碼解決問題。代碼中的細微變化,我已將UILabel直接添加到UIScrollView而不是innerview。

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

scrollView.AddSubview(lViewallLabel); 

這個post幫我解決了這個問題。