开发者

iPhone Gestures Adding 2 at once

Objective C answers are fine too. This is in C# Monotouch.

Currently I am using this code to add 2 gestures (left / right) to my WebView. Works fine.

Can I combine this into less code though to indicate that both gestures go to the same action?

//LEFT
UISwipeGestureRecognizer sgr = new UISwipeGestureRecognizer ();
sgr.AddTarget (this, MainViewController.MySelector);
sgr.Direction = UISwipeGestureRecognizerDirection.Left;
sgr.Delegate = new SwipeRecognizerDelegate ();
this.View.AddGestureRecognizer (sgr);

//RIGHT
UISwipeGestureRecognizer sgrRight = new UISwipeGestureRecognizer ();
sgrRight.AddTarget (this, MainViewController.MySelector);
sgrRight.Direction = UISwipeGestureRecognizerDirection.Right;
sgrRight.Delegate = new SwipeRecog开发者_如何学PythonnizerDelegate ();
this.View.AddGestureRecognizer (sgrRight);


You could try this version, which is shorter and takes advantage of C# lambdas:

UISwipeGestureRecognizer sgr = new UISwipeGestureRecognizer ();
sgr.Action = delegate {
   // Your handler goes here
});
sgr.Direction = UISwipeGestureRecognizerDirection.Left | 
                UISwipeGestureRecognizerDirection.Right;
this.View.AddGestureRecognizer (sgr);


In ObjC you'd use the bitwise or operator with the directions to include them both. But as for whichever language you're using, you'll be lucky to get much support from any experienced iOS developer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜