我在解决xamarin问题时遇到了一些困难。在我的viewcontroller的ViewDidAppear中,我正在注册一个轻击手势。
ProfileViewController
public override void ViewDidAppear (bool animated)
{
base.ViewDidAppear (animated);
if (!_hasUi) {
SetUi ();
}
SetProfile ();
if (CheckConnectivityStatus ()) {
SetGameData ();
if (_hasRegisteredGestures) return;
//SetGestures();
AssignGesturesToUi();
_hasRegisteredGestures = true;
} else {
HandleWebAPICallError ();
}
}
public void AssignGesturesToUi()
{
_bonusTap = new UITapGestureRecognizer(ShowBonus) { CancelsTouchesInView = false };
_userProfile.VwLevel.MultipleTouchEnabled = false;
_userProfile.VwLevel.UserInteractionEnabled = true;
_userProfile.VwLevel.AddGestureRecognizer(_bonusTap);
}
然后我的ShowBonus方法将tap作为参数。
private void ShowBonus (UITapGestureRecognizer tap)
{
if (tap.State == UIGestureRecognizerState.Cancelled)
return;
_userProfile.VwLevel.UserInteractionEnabled = true;
//RemoveGestures();
var tab = TabBarController as GameTabController;
tab?.SetTabBarVisible(false, true);
var mainStoryboard = UIStoryboard.FromName("Main", null);
var achievementsViewController = (AchievementsViewController)mainStoryboard.InstantiateViewController("AchievementsViewController");
AddChildViewController(achievementsViewController);
achievementsViewController.Achievements = false;
achievementsViewController.View.Transform = CGAffineTransform.MakeScale(0.01f, 0.01f);
achievementsViewController.View.Center = _userProfile.ConvertPointToView(_userProfile.Cup.Center, View);
achievementsViewController.ReturnPoint = achievementsViewController.View.Center;
View.AddSubview(achievementsViewController.View);
achievementsViewController.View.Alpha = 0.0f;
UIView.Animate(0.5f, 0.0f, UIViewAnimationOptions.CurveEaseInOut,
() => {
achievementsViewController.View.Transform = CGAffineTransform.MakeScale(1.0f, 1.0f);
achievementsViewController.View.Center = View.Center;
achievementsViewController.View.Alpha = 1.0f;
},
() => {
achievementsViewController.DidMoveToParentViewController(this);
});
}
显示奖金显示个人资料视图前面的另一个视图。如果我快速点击UI,它将触发代码两次。是否有可能即使我快速点击多次,它只会激活一次代码?
答案 0 :(得分:0)
定义DateTime类型的变量lastShowPress并在上次调用ShowBonus时存储它。在ShowBonus开始时检查ShowBonus是否被调用,比如10秒或你需要的任何间隔。如果是 - 返回,如果不是 - 存储时间并执行。您需要通过锁定对象保护此变量/检查。