在iOS视图中将OxyPlot旋转90度
我已经尝试了所有我能在别处找到的建议,我也尝试了你能在下面看到的每一种代码排列,我只是无法破解这个 情节本身很好,没有问题。我的应用程序中有一个特定的屏幕,我想在这个视图上绘制一个OxyPlot,但旋转90度以更好地适应数据(由于各种原因,应用程序当前锁定为纵向) 视图中的代码是:在iOS视图中将OxyPlot旋转90度,ios,xamarin,oxyplot,Ios,Xamarin,Oxyplot,我已经尝试了所有我能在别处找到的建议,我也尝试了你能在下面看到的每一种代码排列,我只是无法破解这个 情节本身很好,没有问题。我的应用程序中有一个特定的屏幕,我想在这个视图上绘制一个OxyPlot,但旋转90度以更好地适应数据(由于各种原因,应用程序当前锁定为纵向) 视图中的代码是: private void CreatePlotChart() { var normalRect = new CGRect(0,0, View.Frame.Width, View.Frame.Height);
private void CreatePlotChart()
{
var normalRect = new CGRect(0,0, View.Frame.Width, View.Frame.Height);
var rotatedRect = new CGRect(0, 0, View.Frame.Height, View.Frame.Width); // height and width swapped
var plot = new PlotView();
var radians = -90d.ToRadians();
plot.Transform = CGAffineTransform.MakeRotation((nfloat)radians);
// plot.Frame = normalRect;
plot.Model = ViewModel.Model;
// plot.InvalidatePlot(true); // no discernable effect
Add(plot);
// plot.Draw(rotatedRect); // context error
View.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();
View.AddConstraints(
plot.AtTopOf(View),
plot.AtLeftOf(View),
plot.WithSameHeight(View),
plot.WithSameWidth(View),
plot.AtBottomOf(View)
);
}
上面的代码生成如下所示的图表,如果我将rotatedlect
传递给构造函数new PlotView(rotatedlect)
,我也会得到完全相同的图表:
如果我删除约束的使用并像这样传入rotatedRect
:
private void CreatePlotChart()
{
var normalRect = new CGRect(0,0, View.Frame.Width, View.Frame.Height);
var rotatedRect = new CGRect(0, 0, View.Frame.Height, View.Frame.Width); // height and width swapped
var plot = new PlotView(rotatedRect);
var radians = -90d.ToRadians();
plot.Transform = CGAffineTransform.MakeRotation((nfloat)radians);
// plot.Frame = normalRect;
plot.Model = ViewModel.Model;
// plot.InvalidatePlot(true); // no discernable effect
Add(plot);
// plot.Draw(rotatedRect); // context error
// View.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();
//View.AddConstraints(
// plot.AtTopOf(View),
// plot.AtLeftOf(View),
// plot.WithSameHeight(View),
// plot.WithSameWidth(View),
// plot.AtBottomOf(View)
// );
}
我离理想效果更近了,如下所示:
如果我执行另一个步骤并将其帧“重置”到缓存的normalRect
,我会更接近它,如下所示:
所有这些尝试都让人感觉太不舒服了。实现我需要的图表操作和保持约束使用以确保正确定位的最佳方法是什么
更新
如果在绘制第一张图表并启动另一个数据选择后,完全相同的代码正确地呈现了图表:
这也是100%可重复的,所以我认为这可能是OxyPlot中的一个错误,或者我使用它的方式的一些奇怪的副作用。尝试旋转图层而不是视图OK,我也会尝试。我刚刚对问题进行了更新。在数据选择后第二次呈现图表时,它的行为符合预期。。。奇怪。很不幸,旋转图层没有起作用。