Düzenle

Aracılığıyla paylaş


UIResponder.CanPerform(Selector, NSObject) Method

Definition

Determines if this UIResponder can perform the specified action. Typically used to probe for editing commands.

[Foundation.Export("canPerformAction:withSender:")]
public virtual bool CanPerform (ObjCRuntime.Selector action, Foundation.NSObject withSender);
abstract member CanPerform : ObjCRuntime.Selector * Foundation.NSObject -> bool
override this.CanPerform : ObjCRuntime.Selector * Foundation.NSObject -> bool

Parameters

action
Selector

The selector that represents the action that is being probed. For editing operations, these selectors are "copy:", "cut:", "delete:", "paste:", "select:", "selectAll:", "toggleBoldface:", "toggleItalics:", "toggleUnderline:".

withSender
NSObject

The object invoking this method.

This parameter can be null.

Returns

True if the specified action can be performed with the specified sender.

Attributes

Remarks

This method should return true if the action specified by the selector can be performed by the object.

//
// Selectable label: a label that shows the "Copy" menu when the user
// long presses
//
public class SelectableLabel : UILabel {

public SelectableLabel (RectangleF rect) : base (rect)
{
UserInteractionEnabled = true;
var gesture = new UILongPressGestureRecognizer (LongPress);
AddGestureRecognizer (gesture);
}

void LongPress (UILongPressGestureRecognizer r)
{
var location = r.LocationInView (r.View);
var menu = UIMenuController.SharedMenuController;

r.View.BecomeFirstResponder ();

menu.SetTargetRect (r.View.Frame, r.View);
menu.SetMenuVisible (true, true);
}


public override bool CanBecomeFirstResponder { 
get { return true; } 
}

Selector copyAction = new Selector ("copy");

public override bool CanPerform (Selector action, NSObject withSender)
{
if (action == copyAction);
return true;
return false;
}

public override void Copy (NSObject sender)
{
UIPasteboard.General.String = this.Text;
}
}

Applies to