【发布时间】:2015-01-06 10:32:54
【问题描述】:
我尝试在 UIView 中实现一些 UIImageViews 的拖放。它目前正在工作,但您可以将图像视图拖出父级并拖出屏幕。我知道我必须检查视图是否超出了父范围。但我正在努力实现它!有人对这个有经验么?对于 Windows Phone 客户端,只需要以下行;
var dragBehavior = new MouseDragElementBehavior {ConstrainToParentBounds = true};
我当前的手势代码在这里;
private UIPanGestureRecognizer CreateGesture(UIImageView imageView)
{
float dx = 0;
float dy = 0;
var panGesture = new UIPanGestureRecognizer((pg) =>
{
if ((pg.State == UIGestureRecognizerState.Began || pg.State == UIGestureRecognizerState.Changed) && (pg.NumberOfTouches == 1))
{
var p0 = pg.LocationInView(View);
if (dx == 0)
dx = (float)p0.X - (float)imageView.Center.X;
if (dy == 0)
dy = (float)p0.Y - (float)imageView.Center.Y;
float newX = (float)p0.X - dx;
float newY = (float)p0.Y - dy;
var p1 = new PointF(newX, newY);
imageView.Center = p1;
}
else if (pg.State == UIGestureRecognizerState.Ended)
{
dx = 0;
dy = 0;
}
});
return panGesture;
}
【问题讨论】:
标签: ios xcode uiview xamarin.ios xamarin