问题描述
说明
在 iPhone 7 中启用辅助功能旁白时,Xamarin iOS UIVIew 不拖动,因为接触点不正确
重现步骤
预期行为
在启用基于点拖动视图的辅助功能之前,需要获得相同的触摸点。
实际行为
启用辅助功能后无法获得准确的接触点。示例:当可访问性禁用并在特定点触摸视图时,点 (X,Y) 为 7,13,但启用可访问性并在同一点触摸视图,点 (X,Y) 为 50,150
基本信息
VS 2019 测试设备:iPhone XF 版本:4.8
代码
public partial class ViewController : UIViewController
{
public ViewController(IntPtr handle) : base(handle)
{
}
UIImageView image;
private bool touchStartedInside;
public override void ViewDidLoad()
{
base.ViewDidLoad();
UILabel label = new UILabel();
label.Text = "DragDemo";
label.Frame = new CGRect(100,30,50,50);
image = new UIImageView();
image.Frame = new CoreGraphics.CGRect(100,100,100);
image.Image = UIImage.FromBundle("DragMe.png");
View.AddSubviews(label);
View.AddSubviews(image);
// Perform any additional setup after loading the view,typically from a nib.
}
public override void touchesBegan(NSSet touches,UIEvent evt)
{
base.touchesBegan(touches,evt);
// Get the current touch
UITouch touch = touches.AnyObject as UITouch;
if (touch != null)
{
// Getting different touch points when enable and disable the accessiibility voice over.
if (image.Frame.Contains(touch.LocationInView(View)))
{
// Third image touched,prepare to drag
touchStartedInside = true;
}
}
}
public override void touchesCancelled(NSSet touches,UIEvent evt)
{
base.touchesCancelled(touches,evt);
// reset our tracking flags
touchStartedInside = false;
}
public override void touchesEnded(NSSet touches,UIEvent evt)
{
base.touchesEnded(touches,evt);
touchStartedInside = false;
}
public override void touchesMoved(NSSet touches,UIEvent evt)
{
base.touchesMoved(touches,evt);
// get the touch
UITouch touch = touches.AnyObject as UITouch;
if (touch != null)
{
// check to see if the touch started in the dragme image
if (touchStartedInside)
{
// move the shape
nfloat offsetX = touch.PrevIoUsLocationInView(View).X - touch.LocationInView(View).X;
nfloat offsetY = touch.PrevIoUsLocationInView(View).Y - touch.LocationInView(View).Y;
image.Frame = new CGRect(new CGPoint(image.Frame.X - offsetX,image.Frame.Y - offsetY),image.Frame.Size);
}
}
}
public override void DidReceiveMemoryWarning()
{
base.DidReceiveMemoryWarning();
// Release any cached data,images,etc that aren't in use.
}
}
}
示例链接:
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)