本文整理汇总了C#中UIImageView.AddGestureRecognizer方法的典型用法代码示例。如果您正苦于以下问题:C# UIImageView.AddGestureRecognizer方法的具体用法?C# UIImageView.AddGestureRecognizer怎么用?C# UIImageView.AddGestureRecognizer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UIImageView
的用法示例。
在下文中一共展示了UIImageView.AddGestureRecognizer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ViewDidLoad
public override void ViewDidLoad()
{
View.BackgroundColor = UIColor.White;
_imageView = new UIImageView(View.Frame)
{
MultipleTouchEnabled = true,
UserInteractionEnabled = true,
ContentMode = UIViewContentMode.ScaleAspectFit,
AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight
};
var tapGesture = new UITapGestureRecognizer(OnImageTap);
_imageView.AddGestureRecognizer(tapGesture);
var leftSwipe = new UISwipeGestureRecognizer(OnImageSwipe)
{
Direction = UISwipeGestureRecognizerDirection.Left
};
_imageView.AddGestureRecognizer(leftSwipe);
var rigthSwipe = new UISwipeGestureRecognizer(OnImageSwipe)
{
Direction = UISwipeGestureRecognizerDirection.Right
};
_imageView.AddGestureRecognizer(rigthSwipe);
View.AddSubview(_imageView);
PHAsset asset = _imageCache.GetAsset(_image.LocalIdentifier);
UpdateImage(asset);
}
示例2: ViewDidLoad
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
nfloat r = 0;
nfloat dx = 0;
nfloat dy = 0;
using (var image = UIImage.FromFile ("monkey.png")) {
imageView = new UIImageView (image){Frame = new CGRect (new CGPoint(0,0), image.Size)};
imageView.UserInteractionEnabled = true;
View.AddSubview (imageView);
}
rotateGesture = new UIRotationGestureRecognizer ((() => {
if ((rotateGesture.State == UIGestureRecognizerState.Began || rotateGesture.State == UIGestureRecognizerState.Changed) && (rotateGesture.NumberOfTouches == 2)) {
imageView.Transform = CGAffineTransform.MakeRotation (rotateGesture.Rotation + r);
} else if (rotateGesture.State == UIGestureRecognizerState.Ended) {
r += rotateGesture.Rotation;
}
}));
panGesture = new UIPanGestureRecognizer (() => {
if ((panGesture.State == UIGestureRecognizerState.Began || panGesture.State == UIGestureRecognizerState.Changed) && (panGesture.NumberOfTouches == 1)) {
var p0 = panGesture.LocationInView (View);
if (dx == 0)
dx = p0.X - imageView.Center.X;
if (dy == 0)
dy = p0.Y - imageView.Center.Y;
var p1 = new CGPoint (p0.X - dx, p0.Y - dy);
imageView.Center = p1;
} else if (panGesture.State == UIGestureRecognizerState.Ended) {
dx = 0;
dy = 0;
}
});
imageView.AddGestureRecognizer (panGesture);
imageView.AddGestureRecognizer (rotateGesture);
View.BackgroundColor = UIColor.White;
}
示例3: DogViewController
public DogViewController ()
{
var iv = new UIImageView (UIImage.FromBundle ("Dog.jpg"));
iv.UserInteractionEnabled = true;
iv.AddGestureRecognizer (new UITapGestureRecognizer (g => {
DismissViewController (true, null);
}));
View = iv;
}
示例4: MenuButton
public MenuButton(string path, CGRect frame)
{
image = new UIImageView();
image.Image = UIImage.FromFile(path);
image.Frame = frame;
CustomView = image;
image.AddGestureRecognizer(new UITapGestureRecognizer(OnImageClick));
}
示例5: OnElementChanged
// ---------------------------------------------------------------------------
//
// METHODS
//
// ---------------------------------------------------------------------------
//
// Set up the custom renderer. In this case, that means set up the gesture
// recognizer.
//
protected override void OnElementChanged(ElementChangedEventArgs<Image> e) {
base.OnElementChanged (e);
if (e.NewElement != null) {
// Grab the Xamarin.Forms control (not native)
formsElement = e.NewElement as CustomImage;
// Grab the native representation of the Xamarin.Forms control
nativeElement = Control as UIImageView;
// Set up a tap gesture recognizer on the native control
nativeElement.UserInteractionEnabled = true;
UITapGestureRecognizer tgr = new UITapGestureRecognizer (TapHandler);
nativeElement.AddGestureRecognizer (tgr);
}
}
示例6: ViewDidLoad
public override void ViewDidLoad()
{
base.ViewDidLoad();
var homeBackground = new UIImageView(UIImage.FromBundle("Home"));
homeBackground.Frame = View.Frame;
View.AddSubview(homeBackground);
var tapRecognizer = new UITapGestureRecognizer(() =>
{
DismissViewController(true, null);
});
homeBackground.UserInteractionEnabled = true;
homeBackground.AddGestureRecognizer(tapRecognizer);
}
示例7: ViewDidLoad
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
imageView = new UIImageView (View.Bounds) {
UserInteractionEnabled = true
};
imageView.AddGestureRecognizer (new UITapGestureRecognizer ((x)=> {
UpdateImage ();
}));
View.AddSubview (imageView);
sourceImage = UIImage.FromBundle ("DisplayImage");
Console.WriteLine ("Got: {0}", sourceImage);
UpdateImage ();
var alert = new UIAlertView ("Tap to change image effect", "Tap on the change", null, "Dismiss");
alert.Show ();
}
示例8: ViewDidLoad
public override void ViewDidLoad()
{
base.ViewDidLoad();
Title = "Gesture Recognizers";
View.BackgroundColor = UIColor.White;
lblGestureStatus = new UILabel();
lblGestureStatus.Text = "Tap Location: ";
lblGestureStatus.Frame = new RectangleF(0, 350, View.Frame.Width, 44.0f);
imgTapMe = new UIImageView(UIImage.FromBundle("Images/DoubleTapMe.png"));
imgTapMe.UserInteractionEnabled = true;
imgTapMe.Frame = new RectangleF(184, 275, 56, 56);
//TODO: Step 10 - Add a tap gesture recognizer
var tapGestureRecognizer = new UITapGestureRecognizer();
tapGestureRecognizer.AddTarget(
(tg) =>
{
var currTapGesture = (tg as UITapGestureRecognizer);
if (currTapGesture == null) return;
lblGestureStatus.Text = string.Format("Tap Location: @{0}", currTapGesture.LocationOfTouch(0, imgTapMe));
});
tapGestureRecognizer.NumberOfTapsRequired = 2;
imgTapMe.AddGestureRecognizer(tapGestureRecognizer);
imgDragMe = new UIImageView(UIImage.FromBundle("Images/DragMe.png"));
imgDragMe.UserInteractionEnabled = true;
imgDragMe.Frame = new RectangleF(78, 275, 56, 56);
//TODO: Step 11a - Add a pan gesture recognizer for drag motions
imgDragMe.AddGestureRecognizer(new UIPanGestureRecognizer(HandleDrag));
originalImageFrame = imgDragMe.Frame;
View.AddSubviews(new UIView[] { lblGestureStatus, imgDragMe, imgTapMe });
}
示例9: ViewDidLoad
public override void ViewDidLoad()
{
base.ViewDidLoad ();
View.BackgroundColor = UIColor.White;
scrollView = new UIScrollView (View.Bounds) {
BackgroundColor = UIColor.Gray
};
// Setup mats view
marsView = new UIImageView (UIImage.FromBundle ("mars.jpg")){
UserInteractionEnabled = true,
};
marsView.AddGestureRecognizer (new UITapGestureRecognizer (()=> {
// We'll introduce an artifical delay to feel more like MKMapView for this demonstration.
NSTimer.CreateScheduledTimer (new TimeSpan (0, 0, 0, 0, 333), ()=> InvokeOnMainThread (()=> calloutView.DismissCallout (true)));
}));
scrollView.AddSubview (marsView);
scrollView.ContentSize = marsView.Frame.Size;
scrollView.ContentOffset = new PointF (150, 50);
//Setup top Pin
topPin = new MKPinAnnotationView (null, "") {
Center = new PointF (View.Frame.Width/2 + 230, View.Frame.Height/2)
};
topPin.AddGestureRecognizer (new UITapGestureRecognizer (()=> {
// now in this example we're going to introduce an artificial delay in order to make our popup feel identical to MKMapView.
// MKMapView has a delay after tapping so that it can intercept a double-tap for zooming. We don't need that delay but we'll
// add it just so things feel the same.
NSTimer.CreateScheduledTimer (new TimeSpan (0, 0, 0, 0, 333), () => {
InvokeOnMainThread (()=> {
calloutView.ContentView = null; // clear any custom view that was set by another pin
calloutView.BackgroundView = CalloutBackgroundView.SystemBackgroundView; // use the system graphics
// This does all the magic. It present the CalloutView
calloutView.PresentCallout (topPin.Frame, marsView, scrollView, CalloutArrowDirection.Any, true);
// Here's an alternate method that adds the callout *inside* the pin view. This may seem strange, but it's how MKMapView
// does it. It brings the selected pin to the front, then pops up the callout inside the pin's view. This way, the callout
// is "anchored" to the pin itself. Visually, there's no difference; the callout still looks like it's floating outside the pin.
// calloutView.PresentCallout (topPin.Bounds, topPin, scrollView, CalloutArrowDirection.Down, true);
});
});
}));
marsView.AddSubview (topPin);
// Setup disclosure button
var topDisclosure = UIButton.FromType (UIButtonType.DetailDisclosure);
topDisclosure.AddGestureRecognizer (new UITapGestureRecognizer (()=> {
InvokeOnMainThread (()=> new UIAlertView ("Tap!", "You tapped the disclosure button.", null, "Ok", null).Show ());
}));
// Now lets stup our calloutView
calloutView = new CalloutView () {
Title = "Curiosity",
Subtitle = "Mars Rover",
RightAccessoryView = topDisclosure,
CalloutOffset = topPin.CalloutOffset
};
View.AddSubview (scrollView);
}
示例10: SetupPhotos
void SetupPhotos()
{
nfloat height = this.Frame.Size.Height;
nfloat width = this.Frame.Size.Width;
cp_mask = new UIView(new CGRect(0, 0, width, height * Constants.CP_RATIO));
pp_mask = new UIView(new CGRect(width * Constants.PP_X_RATIO, height * Constants.PP_Y_RATIO, height * Constants.PP_RATIO, height * Constants.PP_RATIO));
pp_circle = new UIView(new CGRect(pp_mask.Frame.Location.X - Constants.PP_BUFF, pp_mask.Frame.Location.Y - Constants.PP_BUFF, pp_mask.Frame.Size.Width + 2 * Constants.PP_BUFF, pp_mask.Frame.Size.Height + 2 * Constants.PP_BUFF));
pp_circle.BackgroundColor = UIColor.White;
pp_circle.Layer.CornerRadius = pp_circle.Frame.Size.Height / 2;
pp_mask.Layer.CornerRadius = pp_mask.Frame.Size.Height / 2;
cp_mask.BackgroundColor = new UIColor(0.98f, 0.98f, 0.98f, 1);
nfloat cornerRadius = this.Layer.CornerRadius;
UIBezierPath maskPath = UIBezierPath.FromRoundedRect(cp_mask.Bounds, UIRectCorner.TopLeft | UIRectCorner.TopRight, new CGSize(cornerRadius, cornerRadius));
CAShapeLayer maskLayer = new CAShapeLayer();
maskLayer.Frame = cp_mask.Bounds;
maskLayer.Path = maskPath.CGPath;
cp_mask.Layer.Mask = maskLayer;
UIBlurEffect blurEffect = UIBlurEffect.FromStyle(UIBlurEffectStyle.Light);
visualEffectView = new UIVisualEffectView(blurEffect);
visualEffectView.Frame = cp_mask.Frame;
visualEffectView.Alpha = 0;
profileImageView = new UIImageView();
profileImageView.Frame = new CGRect(0, 0, pp_mask.Frame.Size.Width, pp_mask.Frame.Size.Height);
coverImageView = new UIImageView();
coverImageView.Frame = cp_mask.Frame;
coverImageView.ContentMode = UIViewContentMode.ScaleAspectFill;
cp_mask.AddSubview(coverImageView);
pp_mask.AddSubview(profileImageView);
cp_mask.ClipsToBounds = true;
pp_mask.ClipsToBounds = true;
// setup the label
nfloat titleLabelX = pp_circle.Frame.Location.X + pp_circle.Frame.Size.Width;
titleLabel = new UILabel(new CGRect(titleLabelX, cp_mask.Frame.Size.Height + 7, this.Frame.Size.Width - titleLabelX, 26));
titleLabel.AdjustsFontSizeToFitWidth = false;
titleLabel.LineBreakMode = UILineBreakMode.Clip;
titleLabel.Font = UIFont.FromName("HelveticaNeue-Light", 20);
titleLabel.TextColor = new UIColor(0, 0, 0, 0.8f);
titleLabel.Text = "Title Label";
titleLabel.UserInteractionEnabled = true;
UITapGestureRecognizer tapGesture = new UITapGestureRecognizer(this.TitleLabelTap);
titleLabel.AddGestureRecognizer(tapGesture);
coverImageView.UserInteractionEnabled = true;
UITapGestureRecognizer tapGestureCover = new UITapGestureRecognizer(this.CoverPhotoTap);
coverImageView.AddGestureRecognizer(tapGestureCover);
profileImageView.UserInteractionEnabled = true;
UITapGestureRecognizer tapGestureProfile = new UITapGestureRecognizer(this.ProfilePhotoTap);
profileImageView.AddGestureRecognizer(tapGestureProfile);
this.AddSubview(titleLabel);
this.AddSubview(cp_mask);
this.AddSubview(pp_circle);
this.AddSubview(pp_mask);
coverImageView.AddSubview(visualEffectView);
}
示例11: Show
/// <summary>
/// Show Menu.
/// </summary>
public void Show()
{
if (isVisible) return;
isVisible = true;
WillShowMenu(true);
if (HideStatusBar)
UIApplication.SharedApplication.SetStatusBarHidden(true, false);
originalSize = internalTopView.View.Frame.Size;
SizeF size = new SizeF(originalSize.Width / 2f, originalSize.Height / 2f);
float x = (View.Frame.Width - (size.Width / 2));
float y = (View.Frame.Height - size.Height) / 2f;
if (showTrail)
{
snapshotTrail = new UIImageView(TakeSnapshot(internalTopView.View));
snapshotTrail.Frame = new RectangleF(0, 0, originalSize.Width, originalSize.Height);
snapshotTrail.Alpha = 0.2f;
View.AddSubview(snapshotTrail);
}
snapshot = new UIImageView(TakeSnapshot(internalTopView.View));
snapshot.Frame = new RectangleF(0, 0, originalSize.Width, originalSize.Height);
snapshot.UserInteractionEnabled = true;
View.AddSubview(snapshot);
internalTopView.View.Hidden = true;
UIView.Animate(AnimationSpeed, 0, UIViewAnimationOptions.CurveEaseOut,
delegate
{
snapshot.Frame = new RectangleF(x, y, size.Width, size.Height);
},
delegate
{
snapshot.AddGestureRecognizer(tapGesture);
});
if (showTrail)
{
UIView.Animate(AnimationSpeed, 0.1, UIViewAnimationOptions.CurveEaseOut, delegate
{
snapshotTrail.Frame = new RectangleF(x, y, size.Width, size.Height);
},
null);
}
}
示例12: AddGestureRecognizersToImage
// Add gesture recognizers to one of our images
void AddGestureRecognizersToImage (UIImageView image)
{
image.UserInteractionEnabled = true;
var rotationGesture = new UIRotationGestureRecognizer (RotateImage);
image.AddGestureRecognizer (rotationGesture);
var pinchGesture = new UIPinchGestureRecognizer (ScaleImage);
pinchGesture.Delegate = new GestureDelegate (this);
image.AddGestureRecognizer (pinchGesture);
var panGesture = new UIPanGestureRecognizer (PanImage);
panGesture.MaximumNumberOfTouches = 2;
panGesture.Delegate = new GestureDelegate (this);
image.AddGestureRecognizer (panGesture);
var longPressGesture = new UILongPressGestureRecognizer (ShowResetMenu);
image.AddGestureRecognizer (longPressGesture);
}
示例13: DidTapCaptureButton
void DidTapCaptureButton(object sender, EventArgs e)
{
if (_imageView != null)
{
_imageView.RemoveFromSuperview();
_imageView = null;
}
_imageView = new UIImageView(this.View.Bounds);
_imageView.UserInteractionEnabled = true;
_imageView.ContentMode = UIViewContentMode.Center;
_imageView.BackgroundColor = UIColor.Black;
_imageView.Image = _cropperView.ProcessedImage();
this.View.AddSubview(_imageView);
UITapGestureRecognizer tapRecognizer = new UITapGestureRecognizer(GestureRecognizerDidTap);
_imageView.AddGestureRecognizer(tapRecognizer);
}
示例14: createViewBackButton
private void createViewBackButton()
{
this.viewBackButton = new UIImageView ();
this.viewBackButton.Image = UIImage.FromFile ("Image/backButton.png");
this.viewBackButton.Tag = 1235;
//float with = 60;
this.viewBackButton.Frame = new CoreGraphics.CGRect (20, 10, backButtonWidth, 30);
this.viewBackButton.UserInteractionEnabled = true;
var tapRecognizer = new UITapGestureRecognizer (delegate(UITapGestureRecognizer obj) {
//ViewController.ParentViewController.NavigationController.PopViewController (true);
var rootController = UIApplication.SharedApplication.KeyWindow.RootViewController.ChildViewControllers [0];
var navcontroller = rootController as UINavigationController;
if (navcontroller != null)
rootController = navcontroller.PopViewController (true);
});
viewBackButton.AddGestureRecognizer (tapRecognizer);
/*
ViewController.ParentViewController.NavigationItem.SetLeftBarButtonItem (
new UIBarButtonItem (UIImage.FromFile ("Image/backButton.png")
, UIBarButtonItemStyle.Plain
, (sender, args) => {
this.NavigationController.PopViewController (true);
})
, true);
*/
this.NavigationBar.AddSubview (this.viewBackButton);
}
示例15: InitializeEmptyImage
private void InitializeEmptyImage()
{
this.imageView = new UIImageView (EmptyImageCanvas.MakeEmptyCanvas ()) {
ContentMode = UIViewContentMode.ScaleToFill,
AutoresizingMask = UIViewAutoresizing.All,
Frame = View.Bounds
};
this.View.BackgroundColor = UIColor.Clear;
this.imageView.UserInteractionEnabled = true;
this.View.UserInteractionEnabled = true;
doubletap = new UITapGestureRecognizer (AddImage);
doubletap.NumberOfTapsRequired = 2;
this.dtdelegate = new GestureDelegate ();
doubletap.Delegate = dtdelegate;
imageView.AddGestureRecognizer (doubletap);
longpress = new UILongPressGestureRecognizer (RemoveImage);
longpress.Delegate = dtdelegate;
imageView.AddGestureRecognizer (longpress);
View.AddSubview (imageView);
makeCornersRound ();
}