简体   繁体   中英

Xamarin IOS UILabel Tap Gesture inside UIScrollView not working

I have an UIScrollView and inside this I have an UILabel. I need to detect tap gesture events for the UILabel. At the moment, it' not working. I am new in xamarin IOS, please help. 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.

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

scrollView.AddSubview(lViewallLabel);

This post helped me lot to solve the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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