如何解决由于在 iPhone 7 中启用辅助功能语音时触摸点未正确获取,Xamarin iOS UIVIew 不会拖动 说明重现步骤预期行为实际行为基本信息
说明
在 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 举报,一经查实,本站将立刻删除。